Extraction
Match an HTML tag
Flags: g
Extract simple HTML tags for lightweight text processing.
Pattern
Regular expression
<\/?[A-Za-z][A-Za-z0-9]*\b[^>]*>How it works
Matches opening or closing HTML tags of any name (`<a>`, `<div class="x">`, `</span>`, `<br/>`). Does not attempt to parse attributes or nested content.
Matches
- ▸<div>
- ▸<a href="/x" class="b">
- ▸</span>
- ▸<br/>
Non-matches
- ▸< 1 (space after `<`)
- ▸just text
Common gotchas
Do not use this to parse arbitrary HTML — the language is not regular. Use a DOM parser (`DOMParser` in browsers, BeautifulSoup in Python, Goquery in Go). This pattern is fine for quick text stripping and log processing.
Language snippets
JavaScript
const re = /<\/?[A-Za-z][A-Za-z0-9]*\b[^>]*>/g;
text.replace(re, ""); // strip tagsPython
re.sub(r"<\/?[A-Za-z][A-Za-z0-9]*\b[^>]*>", "", text)Go
re := regexp.MustCompile(`<\/?[A-Za-z][A-Za-z0-9]*\b[^>]*>`)
re.ReplaceAllString(text, "")Java
text.replaceAll("<\\/?[A-Za-z][A-Za-z0-9]*\\b[^>]*>", "")