Verified 2026-09-18

Remove HTML Tags

Matches HTML-looking tags for simple text cleanup.

Use only for simple cleanup of trusted, predictable markup; use an HTML parser for real sanitization or transformation.

regexhtmltext

Find

<[^>]*>

Find (regex)

<[^>]*>

Replace (text)

HTML is not a regular language in the practical sense needed for robust parsing. This pattern is convenient for basic cleanup, but it should never be treated as an XSS sanitizer.

Two failure modes matter: the tag contents survive (stripping <script> tags leaves the payload), and an attribute value containing > ends the match early, leaving broken markup. For untrusted input use DOMParser and a sanitizer such as DOMPurify instead.

Common mistakes

  • Using regex to sanitize untrusted HTML.
  • Breaking content containing angle brackets, comments, attributes, or malformed markup.
Permalink: https://merginit.com/reference/regex/remove-html-tags