Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Reg Ex to find IP address in range

by Kanji (Parson)
on Aug 28, 2003 at 16:46 UTC ( [id://287446]=note: print w/replies, xml ) Need Help??


in reply to Reg Ex to find IP address in range

/\A 111 [.] 255 [.] ( \d | [1234]\d | 5[012345] ) [.] ( \d | [1234]\d | 5[012345] ) \z/x;

...should work ( with /x modifier used to enhance readability ), but if you're not limited to a regexp, a cleaner ( and more easily reusable!) solution would be something like...

return 1 if /\A 111 [.] 255 [.] (\d+) [.] (\d+) \z/x && $1 <= 55 && $2 <= 55;

    --k.


Update: Fixed typo; thanks CS!

Replies are listed 'Best First'.
Re: Re: Reg Ex to find IP address in range
by CombatSquirrel (Hermit) on Aug 28, 2003 at 17:15 UTC
    Errrm... Concerning your RegEx: What about '111.255.11.11'? Should be a valid IP, but is not recognized by your pattern. Probably just a typo, change [234] to [1234]. ;-)
    Cheers, CombatSquirrel.
    Entropy is the tendency of everything going to hell.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found