Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Reg Ex exercise

by Rudolf (Monk)
on Dec 05, 2012 at 16:18 UTC ( #1007318=note: print w/ replies, xml ) Need Help??


in reply to Reg Ex exercise

Hello keesturam, Im sure it could be simplified more, but this is what I came up with! hope it helps :)

if($input =~ /^(-?)((0|\d+).)?\d+$/) { print ("Yes, it is a number\n"); }

UPDATE: don't need that 0 in there,

if($input =~ /^(-?)(\d+.)?\d+$/)


Comment on Re: Reg Ex exercise
Select or Download Code
Re^2: Reg Ex exercise
by keesturam (Initiate) on Dec 05, 2012 at 16:27 UTC

    Thanks Rudolf, that was really helpful.

    I am simply not able to come up with such regexs. I should practice more and more and more..! :-)

Re^2: Reg Ex exercise
by thundergnat (Deacon) on Dec 05, 2012 at 16:49 UTC

    Um... You need to escape that full stop.

    >perl -e "print 'match' if '1234X789' =~ /^(-?)(\d+.)?\d+$/"
    match
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-10-24 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (130 votes), past polls