in reply to curious regex result for perl 5.8.8

From the docs for perlre
NOTE: Failed matches in Perl do not reset the match variables . . .

You can see this more clearly with a slightly modified version of your code where the leading characters are 'xxx' instead of 'zzz'.

my @files=("zzz.21.yy.ccc", "xxx.220.ccc" ); foreach my $name (@files) { my $match="no "; $match="yes" if ( $name =~ /(^[a-z]{3})\.(\d{2,3})\..*\.ccc/) ; print "$match, $name, match1: $1, match2: $2\n"; }
The variables $1 and $2 retain the values they had on the previous successful match.
yes, zzz.21.yy.ccc, match1: zzz, match2: 21 no , xxx.220.ccc, match1: zzz, match2: 21

Replies are listed 'Best First'.
Re^2: curious regex result for perl 5.8.8
by BillKSmith (Monsignor) on Jun 21, 2016 at 02:03 UTC