in reply to Is this a bug in perl regex engine or in my brain?

Hello nikmit,

This (as expected) matches digits in the range 1-249.

But it also matches 00, 01, 02, etc. This is easily fixed by removing the first ? quantifier:

my $regex = '(2[0-4]|1[0-9])?[0-9]';

But I would rather use qr here, together with the /x modifier to make it easier to read:

my $regex = qr{ ( 2[0-4] | 1[0-9] )? [0-9] }x;

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Is this a bug in perl regex engine or in my brain?
by Crackers2 (Parson) on Oct 06, 2015 at 17:49 UTC
    Your regex no longer matches 10-99. You'd need something like
    my $regex = '(2[0-4]|1[0-9]|[1-9])?[0-9]';
    to fix that.