in reply to Re: problem with regex
in thread problem with regex

There should be a "g" at the end of those lines:

my @find = $line[$i] =~ /(?:\A|\t)(abc\d+)(?=\t|\z)/g;
otherwise the regexp matches only once instead of searching for all abc<some_number>.

And if you happen to need to count each of the abc<some_number> separately you can either process the @find:

my @find = $line[$i] =~ /(?:\A|\t)(abc\d+)(?=\t|\z)/ my %count; $count{$_}++ for @find;

or skip building the array

while ($line[i] =~ /(?:\A|\t)(abc\d+)(?=\t|\z)/g) { $count{$1}++; }

Jenda
Enoch was right!
Enjoy the last years of Rome.

Replies are listed 'Best First'.
Re^3: problem with regex
by davido (Cardinal) on Jul 22, 2012 at 08:30 UTC

    I fixed the /g modifiers. They were in my head, and in the tests I linked to, but failed to find their way through my fingers to the keyboard as I posted the node. ;) Thanks for the catch!


    Dave