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
|
|---|