in reply to Extracting multiple matches from Reg Ex
Part 1:
Your problem may be that you've escaped the wrong parens: 1
my($first, $second, $third) = $text =~ /(\([a-z]*\))(?:\s|_|$)/gi; print "$first and $second and $third\n";
Part2:
no warnings 'uninitialized'; my $count = $text =~ s/(\([a-z]*\))(?:\s|_|$)/$1$2/gi; print $count; use warnings;
output, parts 1 and 2:
(network) and (test) and (ifcfg) 3
Part 3:
I'm not at all sure I understand what you want. Please clarify whether you're talking about multiple copies of a parenthesized word or simply "more than 3 parenthesized words in your string."
Update: Oops, meant to say but forgot to write it down, split to an array would also be a valid approach -- perhaps better than above.
Also, though I haven't worked it out, it seems that tr/// might also represent a possibility.
Update2: Adding note 1 -- or the problem may be that I read the OP as seeking to capture the encasing parentheses... which may be true, but is *not* specifically asserted. ...and if 'untrue,' apologies for the initial observation.
|
|---|