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

         /^(\d+)(??{ $1 > 0 && $1 < 256 ? "" : "(?!)" }) \.
           (\d+)(??{ $2 > 0 && $2 < 256 ? "" : "(?!)" }) \.
           (\d+)(??{ $3 > 0 && $3 < 256 ? "" : "(?!)" }) \.
           (\d+)(??{ $4 > 0 && $4 < 256 ? "" : "(?!)" })
          $/x

There's probably a way of collapsing that into one expression
with a {4} after it, but I don't feel like looking for it.
Jeff Pinyan would know.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to