How the pattern works
| Part | Meaning |
|---|---|
< | An opening angle bracket |
[^>]* | Anything except a closing bracket |
> | The closing bracket |
→ "" | Replaced with nothing |
Code examples
JavaScript
const out = text.replace(/<[^>]*>/g, "");Python
import re
out = re.sub(r'<[^>]*>', r'', text)PHP
$out = preg_replace('/<[^>]*>/', '', $text);
Notes and limitations
Quick and handy for plain markup, but it breaks on attributes containing > and doesn’t decode entities like &. In browsers, new DOMParser().parseFromString(html, "text/html").body.textContent is safer.
Regex TesterType a pattern and watch matches highlight live in your test text.
Open the tool Frequently asked questions
What is the regex to remove HTML tags?
/<[^>]*>/g — it is used with find and replace. See the table above for what each part does.
Does it work in Python and PHP?
Yes — the code examples above use the same pattern with re in Python and preg functions in PHP.
How do I test this regex?
Click “Open in Regex Tester” — the pattern, flags and sample text load automatically, and matches highlight as you edit.