in reply to Re: RegEx Headaches
in thread RegEx Headaches

Hmmm, interesting. Now I've got:

DB<23> x $_ 0 'ActionLogs.' DB<24> x /(\d+\.)/g 0 1. 1 2. 2 3. 3 4. 4 5. 5 6. 6 7. 7 8. 8 9.


DB<25> x /(\d+\.)+/g 0 9.

Can anyone tell me why the quantifier makes it match only the last group?

Replies are listed 'Best First'.
Re^3: RegEx Headaches
by kennethk (Abbot) on Jun 19, 2013 at 19:16 UTC
    The quantifier actually makes it match every group; however, it only stores the last match in $1, and thus that's what you see in your return. See Extracting matches in perlretut.

    If you want to extract an arbitrary number of digits sandwiched between decimal points, you can grab them all, and then split the result.

    /((?:\d+\.)+)/g; split /(?<=\.)/, $1;
    [i]n list context, //g returns a list of matched groupings, or if there are no groupings, a list of matches to the whole regexp
    (see Global matching in perlretut) so you could try
    my @res = /(?<=\.)\d+\./g;

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