regexhelper
Test a pattern. Copy a ready-made one. No signup.

Regex to Strip HTML Tags

Copy the pattern, paste your HTML below, and see every tag it highlights for removal. Below the tester: how it works and the one big warning about parsing HTML with regex.

Regex pattern

/<\/?[a-zA-Z][^>]*>/g

This matches any HTML tag so you can remove markup by replacing matches with '' and keeping the text. It works on simple content; it won't correctly handle comments, scripts or malformed HTML.

/ /

What this pattern matches

This matches an HTML start or end tag: an opening angle bracket, an optional slash, a tag name, any attributes, and the closing bracket. Replace matches with an empty string to keep just the text.

How it works, part by part

<\/? — the opening < and an optional / for closing tags.

[a-zA-Z] — a tag must start with a letter (so a < b in prose is not caught).

[^>]*> — any attributes up to the closing bracket.

The big warning

Regex cannot truly parse HTML — comments, CDATA, and > inside attribute values will trip it up. For quick cleanup of simple, trusted markup this is fine; for untrusted input use a real HTML parser or sanitizer.

Use it in your code

Python
import re
text = "Keep this <b>bold</b> text and <a href=\"/x\">this link</a>. Comments like <!-- note --> are a different case."
pattern = r'''<\/?[a-zA-Z][^>]*>'''
for m in re.finditer(pattern, text):
    print(m.group())
JavaScript
const text = "Keep this <b>bold</b> text and <a href=\"/x\">this link</a>. Comments like <!-- note --> are a different case.";
const re = new RegExp(String.raw`<\/?[a-zA-Z][^>]*>`, "g");
console.log(text.match(re));

FAQ

Does it remove closing tags too?

Yes. The optional slash means both <div> and </div> match.

Will it strip attributes?

Yes. Everything up to the closing > is part of the match, including href, class, and style.

Is regex safe for untrusted HTML?

No. For security-sensitive stripping use a dedicated sanitizer; regex misses edge cases like comments and quoted brackets.