At 09:59 PM 6/14/01 +0200, Evgeny Goldin (aka Genie) wrote:

> > /(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?)/;
>
> > 
> /([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-
> > 4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])/)
>
>Wou ! Looks like too many symbols .. Does matching a legal IP worth
>a regex 1km long ? I think it's better to match the IP first,
>split /\./ it to four digits and check if their combination is legal -
>this will allow any sophisticated tests ( for 127.0.0.1 and the like ).
>
>Here's a regex which looks much shorter and flexible to me :
>
>C:\>perl -w
>my $line = 'here is a sample with 123.456.123.456 in the middle';
>my ($ip) = $line =~ m@((?:\d{1,3}\.){3}\d{1,3})@;
>print "[$ip]\n";
>^Z
>[123.456.123.456]

It's simply a matter of how pedantic you wish to be.  The example you 
pasted is not a valid IP address (maximum component value is 255).

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com

Reply via email to