in reply to Matching floats according to perlfaq4
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....
|
|---|