Regexp匹配严格的HTML注释字符串

igo*_*GIS 0 regex comments strip

我试图使用regexp从.html文件中删除所有html注释.我们知道html注释格式是<!-- some comments --> 我创建这样的正则表达式

/<!--.*-->/gs

它的工作原理,但如果在文件中不止一个注释块,这条没有人到另一个块,但都从第一<!--到最后-->

some html tags
<!-- some comments 1 -->
some html tags 2
<!-- some comments 2-->
Run Code Online (Sandbox Code Playgroud)

它剥去了整个

<!-- some comments 1 -->
some html tags 2
<!-- some comments 2-->
Run Code Online (Sandbox Code Playgroud)

我是使用ActionScript语言的代码.任何意见将是有益的.谢谢!

bur*_*ION 6

使用这个正则表达式 /<!--.*?-->/gs


小智 5

使用问号使星号变得懒惰:

/<!--.*?-->/gs
Run Code Online (Sandbox Code Playgroud)