http://qs321.pair.com?node_id=1143957


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:
$ 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
In fact adding any "|<something>" seems to trigger it, i.e.
my $regex = '(2[0-4]|1?[0-9])?[0-9]|a';
gives the exact same result, and additionally matches anything starting with "a".

Aha. Looks like switching from

my $regex = '(2[0-4]|1?[0-9])?[0-9]|25[0-5]';
to
my $regex = qr/(2[0-4]|1?[0-9])?[0-9]|25[0-5]/;
seems to fix it. I don't immediately see why though.