Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: regex capture and quantifiers

by kennethk (Abbot)
on Apr 30, 2013 at 20:49 UTC ( #1031473=note: print w/replies, xml ) Need Help??

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
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031473]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2018-05-27 18:19 GMT
Find Nodes?
    Voting Booth?