Webflags: g

HTML Tag Matcher

Match paired HTML tags and capture the tag name and inner content using a back-reference.

Try it in RegexPro

Pattern

regexJavaScript
/<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>([\s\S]*?)<\/\1>/g

Raw source: <([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>([\s\S]*?)<\/\1>

How it works

Group 1 captures the tag name. [^>]* matches attributes. [\s\S]*? lazily captures inner content. \1 back-references the opening tag name to ensure the closing tag matches.

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
All patternsTest this pattern live →