in reply to [untitled node, ID 303225]

$var =~ /^[123]$/

Abigail

Replies are listed 'Best First'.
Re: Re: Matching a range of integers
by bradcathey (Prior) on Oct 30, 2003 at 13:31 UTC
    Abigail-II, I understand your solution for a variable containing a single digit 1, 2, or 3. However, the 2.14 condition got me wondering how to test at number like that. E.g., how to test that a number of any length contains at least a 1, 2, or 3, but not a decimal point. I've tried everything and I can't decide if it's possible in a regex to say "if this, but not this." Theoretically: 1|2|3 && [^\]. I've tried:
    my $string = "278.13"; print "okay\n" if ($string =~ /^1|2|3[^\.]$/);
    and a dozen others. No luck.

        Thanks Abigail-II. I need to remember the left to right rule from the Camel book, et al!
303233
by Samn (Monk) on Oct 30, 2003 at 10:16 UTC