in reply to Extracting multiple matches from Reg Ex
I would also like it to count how many matches it makes because the input could possibly have more or less than 3 matches.
Here's how that would look using split:
Now, if your real input ever contains letters between a close paren and a following open paren -- e.g. "(foo) X (bar)" -- this approach will catch those as "pieces" as well. If that's a problem, go with Text::Balanced as suggested above.while (<DATA>) { chomp; my @pieces = grep /[a-z]/i, split /[()]+/; printf( "Got %d pieces from '%s' : %s\n", scalar @pieces, $_, join( ' and ', @pieces )); } __DATA__ (network)(test)(ifcfg) (network) (test)_(ifcfg) (foo).(bar) (one)(two)--(three)/(four),(five)
|
|---|