in reply to Regex woes...

Try this:

/^-?\d{1,3}\.\d/

Update: I suppose it'd only be right to explain it.

You know what the ^ does, and the -? says "Match that minus sign if it's there once or not at all."

Note that, in your code, you've got \d{1-3} where you want \d{1,3}.

adamsj

They laughed at Joan of Arc, but she went right ahead and built it. --Gracie Allen

Replies are listed 'Best First'.
Re: Re: Regex woes...
by sierrathedog04 (Hermit) on Jul 09, 2001 at 04:59 UTC
    I would refine the regex a bit. A number that begins with a zero to the left of the decimal point must be followed by the decimal point. So, even though the questioner does not specify this requirement, I would say:

    (/^-?\d{1,3}\.\d/) && !(/^-?0\d+/)

    I also point out for the questioner's benefit that $_ =~ /myregex/ is redundant. By default a regex operates on $_ when there is no explicit operand.

    And, just for fun, let's allow the number to begin with a '+' or a '-'. Hence:

    (/^[-+]?\d{1,3}\.\d/) && !(/^[-+]?0\d+/)