Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Matching floats according to perlfaq4

by Anonymous Monk
on Sep 25, 2002 at 12:49 UTC ( [id://200609]=note: print w/replies, xml ) Need Help??


in reply to Re: Matching floats according to perlfaq4
in thread Matching floats according to perlfaq4

/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/

==

/^[+-]?(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?$/i

The look-ahead is to ensure that a '.' on its own isn't matched, but that (eg) '.04' and '4.' is. I'm not sure how correct the latter form is. The e+3, E-2 etc bit may or may not match; I don't think (example) '1.2e' on its own is meaningful.

Replies are listed 'Best First'.
Re: Re: Re: Matching floats according to perlfaq4
by Anonymous Monk on Sep 25, 2002 at 12:54 UTC

    ...and of course I meant

    /^ [+-]? ( \d+ (\.\d*)? | \.\d+ ) (e[+-]?\d+)? $/ix

    ... really (whitespace added for readability)

Re: Re: Re: Matching floats according to perlfaq4
by demerphq (Chancellor) on Sep 27, 2002 at 11:28 UTC
    Of course it wont match 1.2e so that isnt a worry. And 4. certainly is meaningful (to perl anwyay). Try it...

    Also as I pointed out in my earlier reply the two regexes are _not_ == to each other. They are similar in that they match or reject similar data, however the parts that they match and the way they get captured for later use are radically different.

    For instance

    /([A-Za-z_0-9])(\w)(\w)/
    matches/rejects the same data as
    /(\w{3})/
    But the utility of the two is totally different....

    :-)

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://200609]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-18 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found