in reply to regex capture and quantifiers

When you have Capture groups with Quantifiers, only the last match is returned. For example,
use strict; use warnings; $_ = '1,2,3,4,5'; print /(,?\d)+/;
will output
,5
The solution for the task your shown here (IMHO) is to capture the entire series of numbers, then split on commas:
use strict; use warnings; my $str = '12/22/2005 20 Notice of Agenda of Matters Scheduled for Hea +ring (related document(s)2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, + 16, [17], 18, 19) Filed by Fubar, Inc.. Hearing scheduled for 4/11/2013 at 11:30 AM'; my ($series) = $str =~ m/\(Related document\(s\)([\]\[\d, ]+)\)/i; my @matches = split /,\s*/, $series; s/\[|\]//g for @matches; print "dollar amp is $&\n"; print "found " . scalar(@matches) . " matches.\n"; foreach (@matches) { print " $_\n"; }

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.