in reply to Re: regex for nested "<"/">'
in thread regex for nested "<"/">'

For balanced begin/end matching, this might do:
$re = qr{ ( (?: (?&OPEN) (?: (?>(?:.*?(?=(?&OPEN)|(?&CLOSE)))) | (?-1) )* (?&CLOSE) ) ) (?(DEFINE) (?<OPEN>\bBEGIN\b) (?<CLOSE>\bEND\b) )}x;

Replies are listed 'Best First'.
Re^3: regex for nested "<"/">'
by clueless newbie (Curate) on Feb 12, 2020 at 22:20 UTC

    You're my hero!

    Now to figure out exactly how it works!