Regexp match strickly html comment string

2019-09-06 11:35发布

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!

2条回答
ら.Afraid
2楼-- · 2019-09-06 11:55

Use the question mark to make the asterisk lazy:

/<!--.*?-->/gs
查看更多
女痞
3楼-- · 2019-09-06 12:06

use this regex /<!--.*?-->/gs

查看更多
登录 后发表回答