in reply to Iterations in regex

toolic is right, with the last plus you ARE matching all words already in the first "iteration" (so /g is useless), but only the last matches can be returned (the ones before are overwritten).

Without the + the /g will produce multiple attempts and return matches for each one.

BTW: did you really mean ,+ ??? Looks weird...

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: Iterations in regex
by vitoco (Hermit) on May 12, 2014 at 17:02 UTC

    Thanks to both of you. I've tried adding and removing the g modifier, but never tried without the last operator.

    The sample code was a simplification of my real problem, where I'm trying to capture one specific record from one kind of table from a set of html documents, where each field has it's own line in the source.

    Doing that way, I had to split the original regex in two:

    1. one to identify the required record by the value of the first field
    2. another to the capture of the data fields

    BTW, the original regex was something like this:

    my ($k, @f) = ($h =~ m!<td.*?>(required_\d+_\d+.txt)</td>\s+(<td.*?> +(.+?)</td>\s+)+</tr>!m);

    Then, the ",+" actually meant whitespace "\s+", but I wanted to make them visible in the output. ;-)