(Quotes are out of order deliberately)

Also, the decimal part of the floating point regex is different from the decimal regex on the previous line. Is there any reason for this inconsistency?

I believe that the reason for the difference is that the two were written by different people with different intentions. I think the author of the floating point matcher originally wanted to be able to parse the value out into its components (and didn't convert it properly for general FAQ use, that or failed to mention the added bonus of the pattern).

Note that $1 is the sign, $2 is the fractional part and $3 is the exponent part and $4 is the numeric part of the exponent. By adding an extra parens we would have $1=sign, $2=integer $3=fraction $4=exponent $5=exponent_number. This simplicity of extracting the compnent parts wouldn't be possible with the decimal matcher pattern (where would you put in the capturing braces?)

At that point jarich asked if the look-ahead ?= should be a clustering ?:.

Absolutely not (as pope has pointed out it will match non numbers). ?= is a zero width look ahead assertion (similar to a \b). Thus it neither captures nor affects the pattern after it (except that the matcher wont get to the stuff following if it fails to match). Its utility is in this situation is to ensure that the \d*(\.\d*)? part matches something (which it need not.), I'm almost certain that this was to simplify the regex so that the above point (about parsing the number into its parts) would be possible. Neither the ?: variation or the decimal number matcher has this splitting ability.

Anyway thats my theory, but the more I look at the FAQ the more I think Im right.

--- demerphq
my friends call me, usually because I'm late....


In reply to Re: Matching floats according to perlfaq4 by demerphq
in thread Matching floats according to perlfaq4 by jmcnamara

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.