ccn has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; no warnings qw /uninitialized/; my $re = qr{\A \( (?: (?> [^()]+ ) # Non-parens without backtracking | (??{ $re }) # Group with matching parens )* \) }x; while (<DATA>) { chomp; print "$_: "; print $& if /$re/; print "\n"; } __DATA__ (*********) (***(*)***) ((***)) (((***))) ((**)**(**)) (((())))
/usr/local/bin/perl -w /home/ccn/ab.pl (*********): (*********) (***(*)***): ((***)): (((***))): ((**)**(**)): (((()))):
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why this regexp doesn't match nested parens?
by broquaint (Abbot) on Apr 26, 2004 at 16:40 UTC | |
by ccn (Vicar) on Apr 26, 2004 at 16:44 UTC | |
|
Re: Why this regexp doesn't match nested parens?
by japhy (Canon) on Apr 26, 2004 at 16:50 UTC | |
by ccn (Vicar) on Apr 26, 2004 at 16:53 UTC | |
|
Re: Why this regexp doesn't match nested parens?
by jryan (Vicar) on Apr 26, 2004 at 19:42 UTC |