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:)


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

In reply to Re: Matching floats according to perlfaq4 by BrowserUk
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.