Jorge Goncalvez wrote:
> Hi, I made a parsing of a file which contains :
> this:
> Adresse IP. . . . . . . . . : 155.132.48.23
> 
> like this to obtain the Ip adress.
> 
> if ($_ =~/Adresse IP/) {
>             $_ =~ s/.+://;
>             
>             $Subnet=$_;
>             
>             push @IPREAL, $_;
>             
>             $_=~ s/(\d+\.\d+\.\d+)\.\d+/$1.0/;
>             
>             push @IP, $_;
>             
> It works but my problem is that parsing works only in french files, but I wanted 
> to make it working in another language like for exemple English.
> I have 
> IP Address. . . . . . . . . : 155.132.114.77 
> 
> How can I improve my regexp   if ($_ =~/Adresse IP/) to check the IP address 
> indepentmently of the language (I know that the searched string contains always 
> "IP" )

Something along those lines might work:

#!/usr/bin/perl -w
use strict;

my (@IPREAL, @IP);

while (<DATA>){

        if ( /.*?IP.*?(?:\. )+:\s([0-9.]+)/ ){
                my $ip = $1;
                push @IPREAL, $ip;
                
                $ip =~ s/(\d+\.\d+\.\d+)\.\d+/$1.0/;
                push @IP, $ip;
                
        }
}


print "IPREAL: @IPREAL\n";
print "IP: @IP\n";

__DATA__

Adresse IP. . . . . . . . . : 155.132.48.23
IP Address. . . . . . . . . : 155.135.48.23
Whatever language IP. . . . : 134.43.12.22

__END__

-- 
briac
        A pair of songbirds 
        nest in the branches of a she-oak 
        tree. A lark nests.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to