HTML コメントを見つける
テキスト内のすべての HTML コメントを見つける
let regexp = /your regexp/g;
let str = `... <!-- My -- comment
test --> .. <!----> ..
`;
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'
コメントの最初 <!-- を見つける必要があります。その後、 -->の最後まで
許容されるバリアントは <!--.*?--> です。怠惰な限定子は、 --> の直前でドットを停止させます。また、ドットが改行を含めるようにフラグ s を追加する必要があります。
そうでなければ、複数行のコメントは検出されません
let regexp = /<!--.*?-->/gs;
let str = `... <!-- My -- comment
test --> .. <!----> ..
`;
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'