in reply to Re^2: Regex for max length float
in thread Regex for max length float

If you say in your OP that 1 is valid then your regex will fail for that value because it expects to find a decimal point. Perhaps \.? making it optional would be better?

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^4: Regex for max length float
by agianni (Hermit) on Mar 14, 2007 at 16:27 UTC

    Hmm... yes, but it's not really just the decimal that's optional, right? It's the decimal and the trailing digits. So something like this:

    $float =~ m/ \A # beggining of string \d{0,$max_lhs} # 0 to $max_lhs digits (?= # non capturing grouping \. # decimal point \d{1,$max_rhs} # 1 to $max_rhs digits )? # grouping is optional \z # end of string /xms;

    should do it, right? I haven't had a chance to test it, but that's the correct use of (?= )?, right?

      (?:...) is non-capturing grouping.
      (?=...) is zero-width positive lookahead, which isn't appropriate here.