Well, let's take this guy apart. We know how the leading -? will be treated, so let's leave it out. Then we get two paths that this regex can follow:

(?=\d)\d*\.?\d+$

and

(?=\.\d)\d*\.?\d+$

If the regex takes the first path, we're guaranteed to get at least one digit. This digit must be present in the \d* or \d+ if it goes to the \d*, then we're guaranteed to match the equivalent of

\d+\.?\d+

which will match anything that's comprised of just numbers, and any two numbers with a single period between them.

if it's in the \d+, then we know that there are no periods in the string, since we must have passed through the optional \d* and \.?

so this first path will always match a number number with no fractional portion, or a fractional number with a mandatory leading whole number portion

Now in the other path: (?=\.\d)\d*\.?\d+$

If this regex matches, we're guaranteed to have a period then a number. Since this is a lookahead, that means we've seen past the following \d*, since we can't possibly have picked up a number prior to the period.

So the actual regex in this path is \.\d+, which clearly just matches a number with no preceding 0.

So in any case, I don't think it will match anything other than numbers, as japhy suggests.


In reply to Re: Re: Re: Re: Validating Numbers in CGI Script? by lestrrat
in thread Validating Numbers in CGI Script? by footpad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.