Webflags: g

HTML Comment

Match HTML comments, including multi-line comments and empty ones.

Try it in RegexPro

Pattern

regexJavaScript
/<!--[\s\S]*?-->/g

Raw source: <!--[\s\S]*?-->

How it works

Opens with <!--, then lazily matches any characters (including newlines via [\s\S]) until the first -->. Lazy quantifier prevents greedy spanning across multiple comments.

Examples

Input

<!-- hello -->

Matches

  • <!-- hello -->

Input

<p>keep</p><!-- remove --><span>keep</span>

Matches

  • <!-- remove -->

Input

no comments here

No match

Common use cases

  • Stripping comments from HTML output
  • Build-time template cleanup
  • Detecting conditional IE comments
  • Static site generator preprocessing

Related concepts