Skip to content

Instantly share code, notes, and snippets.

@gray
Last active August 29, 2015 14:06
Show Gist options
  • Save gray/f16ece0398d24724f5ed to your computer and use it in GitHub Desktop.
Save gray/f16ece0398d24724f5ed to your computer and use it in GitHub Desktop.
regex: match nested HTML tags
# This will capture the contents of the div of interest, including any nested div tags.
use 5.010;
my ($div) = $content =~ m[
\Q<div id="matchme">\E
( (?> [^<]++ | <(?!/?div\b) | <div\b[^>]*+>(?1)</div> )*+ )
</div>
]x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment