HTML Tag Matcher
Match paired HTML tags and capture the tag name and inner content using a back-reference.
Try it in RegexPro →Available in
Pattern
<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>([\s\S]*?)<\/\1> (flags: g)Raw source: <([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>([\s\S]*?)<\/\1>
How it works
Examples
Input
<p>Hello world</p>Matches
<p>Hello world</p>
Input
<div class="box">content</div>Matches
<div class="box">content</div>
Common use cases
- •Basic HTML parsing and extraction
- •Template content replacement
- •Static site content scraping
- •Email template processing
Related patterns
HTML Attribute
WebMatch HTML attributes of the form name="value" or name='value' and capture both parts.
HTML Comment
WebMatch HTML comments, including multi-line comments and empty ones.
HTML Entity
WebMatch HTML entities in named (`&`), numeric (`{`), or hex (`💩`) form.
Cookie Header Value
WebParse name=value pairs from an HTTP `Cookie:` header value.
Related concepts
Custom Character Sets: [abc], [a-z], [^abc]
ConceptSquare brackets build a custom character class. [abc] matches any of a, b, or c. [a-z] is a range. A leading ^ negates the set.
Lazy vs. Greedy Quantifiers
ConceptGreedy quantifiers (*, +) consume as much as possible before backtracking. Lazy quantifiers (*?, +?) consume as little as possible.
Capturing Groups and Non-Capturing Groups
ConceptParentheses group tokens and capture the matched substring. (?:...) groups without capturing — use it when you want grouping for quantifiers or alternation but don't need the submatch.
Regex Flags in JavaScript: g, i, m, s, u, y
ConceptFlags modify regex behavior globally. g enables global matching, i makes it case-insensitive, m changes anchor behavior, s dots match newlines, u enables Unicode, y is sticky.
How to Match Across Newlines in JavaScript
How-toThe dot doesn't match newlines by default. Use the s (dotall) flag, or build an explicit [\s\S] alternative for engines that predate s.
How to Escape Regex Special Characters
How-toBackslash-escape any of .^$*+?()[]{}|\ to match them literally. When building a regex from user input, use a full-escape helper function.