Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Need a regex..

by AnomalousMonk (Archbishop)
on May 21, 2012 at 14:33 UTC ( [id://971625]=note: print w/replies, xml ) Need Help??


in reply to Need a regex..

You don't say what should happen with negative numbers, but it's easy enough to exclude them in the same way four-or-more digit patterns are excluded.

Update: A link to Regexp::Common might be helpful.

>perl -wMstrict -le "use Regexp::Common; ;; for my $t (qw( 12.12 123.123 1 12 123 1. 12. 123. .1 .12 .123 0.1 1.0 0.0 1234.0 1234 0.1234 .1234 -123 -.12 -0.1 )) { my $ok = $t =~ m{ \A (?! .* \d{4}) $RE{num}{real} \z }xms; printf qq{%s '$t' \n}, $ok ? 'accept' : 'REJECT'; } " accept '12.12' accept '123.123' accept '1' accept '12' accept '123' accept '1.' accept '12.' accept '123.' accept '.1' accept '.12' accept '.123' accept '0.1' accept '1.0' accept '0.0' REJECT '1234.0' REJECT '1234' REJECT '0.1234' REJECT '.1234' accept '-123' accept '-.12' accept '-0.1'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found