0

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!

igorGIS
  • 1,888
  • 4
  • 27
  • 41

2 Answers2

6

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

burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
5

Use the question mark to make the asterisk lazy:

/<!--.*?-->/gs
aspidistra
  • 66
  • 4
  • Thanks! It works right now! Can you explain please what this question mark do for this regexp? – igorGIS Jul 04 '12 at 14:03
  • The question mark makes the asterisk character [lazy](http://en.wikipedia.org/wiki/Regular_expression#Lazy_quantification). As in "do as little work as possible before stopping". – aspidistra Jul 04 '12 at 14:22