Try for example
$ip = join '.',map {int} split /\./,$oldip;
or (if you resist on a regular expression)
$oldip =~ s/(?:^0+|(\.)0+([1-9]+)|(\.0)00)/$1.$2 || $3/eg;
JB


-----Original Message-----
From: CARPENTER,STEPHEN (HP-Corvallis,ex1)
[mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 17, 2002 1:25 AM
To: '[EMAIL PROTECTED]'
Subject: Regular expression for an IPv4 address

Hi,
        I'm a beginner with Perl and I'm sure this has been done before:
I
would like to take a string like this '001.202.033.400' and turn it into
'1.202.33.400'. In other words, strip leading zeros from each octet of
an IP
address. I could just split each piece into a different variable, do it,
and
then recombine, but is seems like a one line regular expression could
work
here instead. Thanks to all who reply!

StephenC.
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to