I allowed more than one \d digit, with \d+.
It took me a while to grok it, but the original regex did allow more than one digit, and also captures it. That's because there is a \d in the character class, and the character class is quantified with a *. However this also allows more than one dot or more than one e, so it recognizes Ee.3 as a number.
I agree that your regex is much better to read, but it doesn't allowe numbers before the exponential (I guess that's what the e in the regex is supposed to mean).
Further refinements could use Regex::Common's number regex, or this regex, which parses numbers according to the JSON number specification:
my $number = qr{ -? (?: 0 | [1-9] [0-9]* ) (?: \. [0-9]+ )? (?: [eE] [+-]? [0-9] )? }x;
(might be a bit too restrictive in some cases for parsing numbers "in the wild", but still a good inspiration).
In reply to Re^2: Extraction number from Text
by moritz
in thread Extraction number from Text
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |