in reply to Extracting multiple match and reorganizing order with Regex
Hello,
You should take advantage of the regex capture variables, $1, $2, etc.
Try something like:
foreach my $test (@test) { my ($condition,$persons) = ($2,$3) if($test =~ /(positive for )?(\w ++).*\((.*)\)/i); # $1 capture will either be "positive for" or empty $persons =~ s/\s+//g; # omit spaces $persons =~ s/,/;/g; # changes any commas to semi-colons to have a + common separator my @persons = split /;/, $persons; foreach my $person (@persons) { print "$person\t|| $condition\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extracting multiple match and reorganizing order with Regex
by NewMonk2Perl (Sexton) on Apr 19, 2016 at 00:24 UTC |