问题
I'am trying to use regexp to strip all html comments from .html file.
As we know html comments format are <!-- some comments -->
I've create such regexp
/<!--.*-->/gs
It works, but if there is more than one comment block in file, it strips no one to another block, but all from first <!--
to last -->
F.e.
some html tags
<!-- some comments 1 -->
some html tags 2
<!-- some comments 2-->
It strips entire
<!-- some comments 1 -->
some html tags 2
<!-- some comments 2-->
I'am code with ActionScript language. Any advice would be helpful. Thanks!
回答1:
Use the question mark to make the asterisk lazy:
/<!--.*?-->/gs
回答2:
use this regex /<!--.*?-->/gs
来源:https://stackoverflow.com/questions/11329720/regexp-match-strickly-html-comment-string