in reply to search for matching parentheses

I use this regex to match (but not capture) nested parens. It's from the Camel, 3rd. ed., p. 314.

my $np; $np = qr{ \( (?: (?> [^()]+ ) | (??{ $np }) )* \) }x;

Replies are listed 'Best First'.
Re^2: search for matching parentheses
by smammy (Novice) on Oct 20, 2006 at 16:14 UTC

    I suppose you could use $np like this:

    while (m/\G.*?(\w+)($np)/g) { my $name = $1; # get rid out outermost parens my $value = substr($2,1,length($value)-1); print "name=$name value=$value\n"; }