We just discovered an error in some code where the programmer used the equivalent (.)+ When they were supposed to use (.+) . A simple fix, but we cannot explain the behavior of (.)+ . Can someone explain why this matches "e", the last letter, not "b", the first letter after "a" in the regular expression? How would you explain (.)+ ?
my $s = 'abcde'; if ($s =~ m{ a (.)+ }x ){ print "s '$s' matched '$1'\n"; }else{ print "total match fail\n"; } __END__ output: s 'abcde' matched 'e'
source share