which prints:use strict; use warnings; use Regexp::Common qw(balanced); my @streams = ( '(aaa) (bbb (ccc( ddd) eee)) (fff)', ' (a) ((bc (d)) ef) h', '(a)', '(a) ', '(a) (bc)', '', ); my $PATTERN = $RE{balanced}{-keep}; for my $input (@streams) { print qq("$input" => ); my @pieces = ($input =~ /$PATTERN/g); printf qq(%s\n), join qq( ), map {qq("$_")} @pieces; }
This assumes that you had a typo in your post and you actually want balanced parens. Cheers."(aaa) (bbb (ccc( ddd) eee)) (fff)" => "(aaa)" "(bbb (ccc( ddd) eee))" + "(fff)" " (a) ((bc (d)) ef) h" => "(a)" "((bc (d)) ef)" "(a)" => "(a)" "(a) " => "(a)" "(a) (bc)" => "(a)" "(bc)" "" =>
In reply to Re: regex to parse (nested) parenthesis delimited string?
by fenLisesi
in thread regex to parse (nested) parenthesis delimited string?
by varian
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |