私は、文字列正規表現で特殊文字列内の部分文字列を見つけるにはどうすればよいですか?
element : 1
Description
This is the description of item 1
___________________
element : 2
Description
This is the description of item 2
______________________
これがそのコードですがあります(包括的または排他的にそうでない
var string = "element : 1\n\nDescription\nThis is the description of item 1\n_________________\n\nelement : 2\n\nDescription\nThis is the description of item 2\n____________________________"
と私は正規表現でelement : 1
からelement : 2
に始まる部分文字列を抽出することができるようにしたいが今の問題)
私は、次のコードを使用しますが、それはまだ動作しません:
var regexStr = /element : 1\s*\n(.*)element : 2/
var rx = new RegExp(regexStr, "i")
console.log(string.match(rx)); //null
これは正規表現エディタで完全に機能しますが、なぜここでは動作しないのですか? https://es6console.com/jb8g6b5d/ –
@YouMa: 'multiline'フラグを追加する必要があります:' .../im' https://es6console.com/jb8h1ner/を参照してください。 – Jan