Regex to Extract HTML Tags

All patterns
Extraction18 chars · /g

Regex to Extract HTML Tags

Useful when you need quick tag-level extraction for diagnostics, not full HTML parsing. It matches opening and closing tags with their attributes.

The expression

/<\/?[A-Za-z][^>]*>/g

How to read it

A negated class [^ … ] matches anything except the listed characters.

gglobal — keep going after the first match instead of stopping

Find matches in your own text

no input
Try:

This expression is unanchored, so it finds every occurrence anywhere in the text. Highlighted runs are what a replace call would rewrite.

Examples, checked in your browser

4/4 verified

<div class="note">

Matches.

</section>

Matches.

plain text only

No match — this is the kind of input the pattern rejects.

2 < 5

No match — this is the kind of input the pattern rejects.

Use it in code

3 languages
JavaScript
const regex = /<\/?[A-Za-z][^>]*>/g;
regex.test(input);
Python
import re
pattern = re.compile(r"<\/?[A-Za-z][^>]*>")
bool(pattern.search(input))
Go
re := regexp.MustCompile("<\\/?[A-Za-z][^>]*>")
matched := re.MatchString(input)

Other extraction patterns

4
GroupExtraction
Flags/g
Examples4
SafetyOK