in reply to Regexp for range of numbers

My previous answer is wrong, because variables are interpolated at the time the regex is created. This relatively compact expression works, though:
use strict; use warnings; my @nums = (100,-3,150,-2,-1,256, 280, 254);; foreach my $n (@nums) { print "$n: ", ($n !~ /^1?\d{1,2}$|^2(?:[0-4]\d|5[0-5])$/) ? 'fail' : 'pass'; }

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Regexp for range of numbers
by Anonymous Monk on Apr 05, 2005 at 12:54 UTC
    That would match: "1\N{TIBETAN DIGIT ONE}\N{TIBETAN DIGIT ONE}", but not "\N{TIBETAN DIGIT ONE}1\N{TIBETAN DIGIT ONE}". Doesn't seem fair to the Dalai Lama to me!

    You need to use use charnames ':full' to use \N in the way presented.