Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Don't Use Regular Expressions To Parse IP Addresses!

by sieve (Initiate)
on May 18, 2007 at 20:25 UTC ( #616269=note: print w/ replies, xml ) Need Help??


in reply to Don't Use Regular Expressions To Parse IP Addresses!

If you do use a regular expressions to parse IPv4 in decimal, you could use:

(1?\d\d?|2[0-4]\d|25[0-5])(\.(1?\d\d?|2[0-4]\d|25[0-5])){3}


Comment on Re: Don't Use Regular Expressions To Parse IP Addresses!
Download Code
Re^2: Don't Use Regular Expressions To Parse IP Addresses!
by Anonymous Monk on Nov 08, 2007 at 00:07 UTC
    Not really - the above regex is wrong. Try it on 10.76.110.219 and it will match only 10.76.110.21 (since 1?\d\d? will match 21 and stop and not look for the 2[0-4]\d rule)
      It works inside the correct context. For example, if you supply a leading ^ and trailing $ then all is well. You have to supply your own context.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2015-07-03 11:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (51 votes), past polls