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][^>]*>/gHow to read it
A negated class [^ … ] matches anything except the listed characters.
g — global — keep going after the first match instead of stopping
Find matches in your own text
no inputTry:
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 languagesJavaScript
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
4GroupExtraction
Flags/g
Examples4
SafetyOK