in reply to Re: Is this a bug in perl regex engine or in my brain?
in thread Is this a bug in perl regex engine or in my brain?
Weird. I can reproduce OPs issue:
In fact adding any "|<something>" seems to trigger it, i.e.$ cat /tmp/x my $regex = '(2[0-4]|1?[0-9])?[0-9]|25[0-5]'; while (<>) { chomp; if ($_ =~ /^$regex$/) { print "$_ matched\n"; } else { print "$_ did not match\n"; } } $ perl /tmp/x 100 100 matched 200 200 matched 300 300 matched ^C
gives the exact same result, and additionally matches anything starting with "a".my $regex = '(2[0-4]|1?[0-9])?[0-9]|a';
Aha. Looks like switching from
tomy $regex = '(2[0-4]|1?[0-9])?[0-9]|25[0-5]';
seems to fix it. I don't immediately see why though.my $regex = qr/(2[0-4]|1?[0-9])?[0-9]|25[0-5]/;
In Section
Seekers of Perl Wisdom