Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: (Golf) Expression for matching numeric IP addresses

by hv (Prior)
on Aug 10, 2004 at 13:32 UTC ( [id://381576] : note . print w/replies, xml ) Need Help??


in reply to (Golf) Expression for matching numeric IP addresses

Here's a different approach specifically for the 4-element dotted form:

(eval$_)=~/^[\0-\xff]{4}\z/

This requires perl-5.6.0 or later; extending it for the other forms becomes rather uglier:

(eval"0.0.$_")=~/^\0\0(.|[\0-\xff]([\0-\x{ffffff}]|[\0-\xff]([\0-\x{ +ffff}]|[\0-\xff]{2})))\z/s

Of course the usual caveats about eval apply, but this is golf ...

Hugo