开发者

regular expression to remove comment javascript

I am using below regular 开发者_StackOverflow中文版expression to remove comments from string

<\!{1}\-{2}(.*?)\-{2}\s*>

This is working fine except for mult-iline string

var search = '<\!{1}\-{2}(.*?)\-{2}\s*>';

  var re = new RegExp(search, "gm");

  var subject = <multi-line string>;
  result = subject.replace(re, '');

what should I do to get it working with multiline strings


. does not allow linebreaks.

This one should work:

^(<\!\-{2})((.|\s)*?)\-{2}>$

Fix:

<!--[\S\s]*?-->

I removed the \s at the beginning and the end of the expression and added it in the middle so multiline-comments are allowed.

But you shoud have a look at BartKs comment ;)

regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜