On Fri, Nov 12, 2004 at 03:18:50PM -0000, Peter Scott wrote: > In article <[EMAIL PROTECTED]>, > [EMAIL PROTECTED] (Ing. Branislav Gerzo) writes: > >anyone knows how looks _good_ ip adress regexp ? > >I use something like: > > > >(\d{1,3}\.){3}\d{1,3} > > > >but that also matches for example 888.777.444.222, which is of course > >not good ip adress. I don't want use any module for this, I only want > >fing proper regular expression for IPs. I thought about that a bit, > >and maybe that regexp should looks like this, it is a bit tricky: > > > >^(2[0-5]{2}|1\d{2}|[1-9]\d|[1-9])\.((2[0-5]{2}|1\d{2}|[1-9]\d|\d)\.){2}(2[0-5]{2}|1\d{2}|[1-9]\d|\d)$ > > > >do you think, it is OK ? For me works good, but maybe you have > >something shorter :) > > This isn't shorter, but it is easier to understand :-)
And thus more likely to be correct. Try matching 1.1.1.246 for example. > /^(\d+)(??{ $1 > 0 && $1 < 256 ? "" : "(?!)" }) \. > (\d+)(??{ $2 > 0 && $2 < 256 ? "" : "(?!)" }) \. > (\d+)(??{ $3 > 0 && $3 < 256 ? "" : "(?!)" }) \. > (\d+)(??{ $4 > 0 && $4 < 256 ? "" : "(?!)" }) > $/x You might want to match addresses such as 127.1 or 2130706433. (Try pinging them.) The easiest way to do that might be to convert them into the form you are expecting: perl -MSocket -le 'print inet_ntoa inet_aton $_ for @ARGV' 127.1 2130706433 -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>