Regex to remove HTML tags

Use /<[^>]*>/g with find and replace. Every example below is tested against the pattern, and you can open it in the Regex Tester with the samples preloaded.

Updated

Before

<p>Hello <strong>world</strong>!</p>

After (replace with nothing)

Hello world!

How the pattern works

PartMeaning
<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 &amp;. 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.