Skip to main content
Regexflux

HTML Comment

beginner

Matches HTML comments including multi-line content.

htmlcommentparsing

Pattern

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

Try It

0 of 6 strings matched

Explanation

Matches HTML comments from <!-- to the next -->. Uses [\s\S]*? (non-greedy any character including newlines) to capture multi-line comments.

Test Strings

Matching

  • <!-- comment -->
  • <!-- multi line comment -->
  • <!-- TODO: fix this -->

Non-matching

  • // comment
  • /* comment */
  • <! not a comment >

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /<!--[\s\S]*?-->/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns