At the risk of once again showing my lack of aptitude for regexes, below is what I have currently settled on. It handles all the cases you list, accepting or rejecting them as appropriate.
This seems like a good opportunity to get another set of eyes to look it over.
my $num = qr! [+-]? (?: \d*? )? (?: (?<=\d)\.? | \.?(?=\d) ) (?: \d*?)? (?: \d[Ee] (?: [+-]?\d+ ) )? !ox;
I'm sure there is something wrong with it, but so far it has passed everything I have throw at it.
It was ponted out to me (thankyou sauoq) that this only works if used in a context where it is tightly anchored on both ends.
Minimally, m/^$num$/o.
Note: \b wont work.
For my current learning exercise, that is fine as it will always be used as a part of a larger regex that will so constrain it.
If anyone wants to point out how to modify it to make it work without anchoring, I like to see and note the changes for my ed.
For 'real work' I would use Regex::common of course, especially given it heritage and guardianship. Now if only there was a Regex::Uncommon that did everything else, I wouldn't have to learn regexes at all:)
In reply to Re: Matching floats according to perlfaq4
by BrowserUk
in thread Matching floats according to perlfaq4
by jmcnamara
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |