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.

/ /

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.

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.