in reply to Re: regex only matching from last match
in thread regex only matching from last match

Further to jwkrahn's reply, consider:
>perl -wMstrict -le "my $str = '123 456 789'; print qq{1st match: $1} if $str =~ m{ (\d{3}) }xmsg; print qq{2nd match: $1} if $str =~ m{ (\d{3}) }xmsg; print qq{3rd match: $1} if $str =~ m{ (\d{3}) }xmsg; " 1st match: 123 2nd match: 456 3rd match: 789
Try those matches without the  //g modifier.

Replies are listed 'Best First'.
Re^3: regex only matching from last match
by Foxpond Hollow (Sexton) on Sep 24, 2009 at 16:44 UTC
    Thanks AnomalousMonk and jwkrahn, this explained it perfectly.