in reply to Regexp for Match Brackets

This kind of match is notoriously hard to perform. Try some dedicated module like Text::Balanced. OTOH I'm sure I saw at least one very in-depth article explaining how to do it with regexen. I can't remember where to find it. I bet japhy knows, though...

Replies are listed 'Best First'.
Re^2: Regexp for Match Brackets
by johngg (Canon) on May 05, 2006 at 09:48 UTC
Re^2: Regexp for Match Brackets
by japhy (Canon) on May 05, 2006 at 13:56 UTC
    WHO HAS WAKED ME FROM MY SLUMBER?

    Oh, it's blazar. Simply put, to do it with regexes, you'd do something like:

    my $paren_rx; $paren_rx = qr{ \( (?: (??{ $paren_rx }) # either match another paren-set | (?s: [^\\()]+ | \\. )+ # or match non-parens (or escaped parens +) )? \) }x; my ($chunk) = $string =~ /((??{$paren_rx}))/;
    It's not kid-tested, nor mother-approved, but it feels right, and that's where it counts. In the gut. Long live truthiness. Stephen Colbert++.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

      Yes, but I seem to remember an article, perhaps downloadable in .pdf form that explained "this kinda things" in detail and from step to step. The OP could be interested in it...