use strict;
my $str = '0
1991 (38.26%)
1018 (41.52%)
438 (35.12%)
771 (35.16%)
244 (35.72%)
343 (32.48%)
316 (40.51%)
177 (33.84%)
133 (41.18%)
792 (35.92%)
3190 (61.30%)
1426 (58.16%)
803 (64.39%)
1415 (64.52%)
436 (63.84%)
711 (67.33%)
463 (59.36%)
345 (65.97%)
187 (57.89%)
1403 (63.63%)
44.00 [38.00 - 50.00]
43.00 [37.00 - 49.00]
43.00 [37.00 - 49.00]
44.00 [38.00 - 50.00]
44.00 [39.00 - 50.00]
44.00 [38.00 - 50.00]
43.00 [37.00 - 49.00]
45.00 [39.00 - 51.00]
44.00 [37.00 - 50.00]
45.00 [38.00 - 51.00]
';
my $regex = qr/((?<=\()\S+(?=%\))|^\S+(?=\s\[))/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html