← Back to all regex patterns
Replace
Low backtracking risk

Regex to Remove HTML Comments

Use this in cleanup scripts when you need to strip comment blocks from HTML exports or email templates.

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

Try this pattern

Matches current input
<!-- note -->

1 match found in the current text.

Passing examples

  • <!-- note -->
  • <div><!-- remove me --></div>

Failing examples

  • <div>No comments</div>
  • <!DOCTYPE html>

Code examples

JavaScript
const regex = /<!--[\s\S]*?-->/g;
regex.test(input);
Python
import re
pattern = re.compile(r"<!--[\s\S]*?-->")
bool(pattern.search(input))
Go
re := regexp.MustCompile("<!--[\\s\\S]*?-->")
matched := re.MatchString(input)

Related Replace Patterns