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!

1
  • you need .+? for this, not .* Commented Jul 4, 2012 at 13:08

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

This won't match multi-lines comments.
5

Use the question mark to make the asterisk lazy:

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

2 Comments

Thanks! It works right now! Can you explain please what this question mark do for this regexp?
The question mark makes the asterisk character lazy. As in "do as little work as possible before stopping".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.