On May 27, 2013 1:02 PM, "Dr.Ruud" <rvtol+use...@isolution.nl> wrote: > > On 26/05/2013 14:40, shawn wilson wrote: > >> Thank y'all, I got to where I want to be: >> https://github.com/ag4ve/geocidr > > > > ... > > or grep { ! m%[0-9\.\/]+% } @{$opts->{ip}} > > or scalar(@{$opts->{ip}}) < 1 > > The '+' in the regexp is superfluous as-is. > (your regexp isn't anchored) > > > You probably meant it more like: > > ... > or !@{$opts->{ip}} > or grep m{[^0-9./]}, @{$opts->{ip}} >
You don't want to grep for anything that isn't a number there. I like the !@arr vs my scalar though. And... You're right on anchoring - I should. But as I'm lastly matching for an IP (with a possible subnet, it should probably be more like: m(^[0-9\./]+$) Or better: m(^[0-9\.]+(?:/(?:[0-3])?[0-9])?$) Or more better: m(^(?:(?:[0-2])?[0-9]{1,2}\.){3}(?:[0-2])?[0-9]{1,2}(?:/(?:[0-3])?[0-9])?$) I know there are some edge cases like 256 octets and 32 bit subnets but that's my 'good enough' IP matching regex (written from a phone, in bed because I'm too lazy to get up and masochistic enough to do it so I hope I didn't error any). I'll make this part better and get ip6 in here.