ThreeMonks has asked for the wisdom of the Perl Monks concerning the following question:
use strict; my $a = '(0,((1,2),3,(4,5),6),7,8)'; my $tail = qr{5\)}; my $matching_parens = qr{ ( # paren group 1 (parens) \( (?: (?> [^()]+ ) # Non-parens without backtracking | (?1) # Recurse to start of paren group 1 )* \) ) .* (?<= $tail ) }x; $a =~ /$matching_parens/; print "$1\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange regex result
by moritz (Cardinal) on Jul 08, 2009 at 15:48 UTC |