文字列内の特定のフレーズを探して、その後すべてを取り出して新しい変数に格納するのが最善の方法です。たとえば場合:javascriptで特定の文字列を抽出する方法
var input= "123|ABC S|peter [email protected]!!234|George K|[email protected]";
予想される出力は次のようになります。
peter [email protected],[email protected]
私はそのコードを試してみました:
var input= "123|ABC S|peter [email protected]!!234|George K|[email protected]";
var result = input.match(/[a-z]+/gi);
document.write(result);
入力文字列は、同じフォーマットであること、それを分割して使用する場合。 var input = "123 | ABC S | peter [email protected]!!234 | George K|[email protected]"; 入力= input.split( '|')、 console.log –
私は文字列の電子メール部分のみを抽出する必要があります:peter s @ xyz.com、george.k @ xyz .com。サンプルコードで提案できますか? – geeta
var input = "123 | ABC S | peter [email protected]!!234 | George K|[email protected]"; input = input.split( '|')、console.log(input [2]、input [4])このコードのouptutはpeter [email protected] !! [email protected]は:ピーター@ xyz.com、george.k @ xyz.com – geeta