Regexp match strickly html comment string

杀马特。学长 韩版系。学妹 提交于 2019-12-25 05:29:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!