Go (RE2)

HTML Tag Matcher in GO

Go (RE2) can't run this pattern out of the box.

Try it in the GO tester →

Why it doesn't work in GO

Go's RE2 engine doesn't support backreferences (`\1`, `\2`, …) for the same linear-time reason.

Workaround

Match the candidate substring with a single capture, then verify the duplication in code; or use JS / Python which both support backreferences.

Pattern

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

How the pattern 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>

Same pattern, other engines

← Back to HTML Tag Matcher overview (all engines)