> -----Original Message-----
> From: Jorge Goncalvez [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, November 27, 2001 10:31 AM
> To: [EMAIL PROTECTED]
> Subject: RE:help on Regex
> 
> 
> Hi I have this:
> 
> my $ip="192.40.54.41";
> 
> $ip=~ s/(\d+\.\d+)\.(\d+\.\d+)/$1\.0/;
           ^^^^^^^^    ^^^^^^^^
           This is $1  This is $2

> 
> print $ip;
> 
> But It didn't work it displays 192.40.0 and I wanted to 
> display 192.40.54.0.
> Why? thanks.

The 192.40 is captured as $1, and in your replacement you
append .0 to that, hence the result 192.40.0

You need either

   $ip=~ s/(\d+\.\d+\.\d+)\.\d+/$1.0/;

Or perhaps the simpler

   $ip =~ s/\d+$/0/;

The latter doesn't attempt to match a set of 4 dotted numbers;
it just changes the last sequence of digits to a 0.

Also, you don't need to escape . in the replacement string.

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

Reply via email to