Bruno Desthuilliers wrote:
MRAB a écrit :
On Oct 19, 5:47 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
Pat a écrit :
(snip)
ip = ip[ :-1 ]
ip =+ '9'
or:
ip = ip[:-1]+"9"
(snip)
>>> re.sub(r'^(((\d+)\.){3})\d+$', "\g<1>9", "192.168.1.1")
'192.168.1.9'
re.sub(r'^(((\d+)\.){3})\d+$
Pat a écrit :
Bruno Desthuilliers wrote:
Pat a écrit :
I have a regexp in Perl that converts the last digit of an ip address
to '9'. This is a very particular case so I don't want to go off on
a tangent of IP octets.
( my $s = $str ) =~ s/((\d+\.){3})\d+/${1}9/ ;
While I can do this in P
Bruno Desthuilliers wrote:
Pat a écrit :
I have a regexp in Perl that converts the last digit of an ip address
to '9'. This is a very particular case so I don't want to go off on
a tangent of IP octets.
( my $s = $str ) =~ s/((\d+\.){3})\d+/${1}9/ ;
While I can do this in Python which acc
MRAB a écrit :
On Oct 19, 5:47 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
Pat a écrit :
(snip)
ip = ip[ :-1 ]
ip =+ '9'
or:
ip = ip[:-1]+"9"
(snip)
>>> re.sub(r'^(((\d+)\.){3})\d+$', "\g<1>9", "192.168.1.1")
'192.168.1.9'
re.sub(r'^(((\d+)\.){3})\d+$', "\g<1>9", "192.168.1.100"
MRAB:
> The regular expression changes the last sequence of digits to
> "9" ("192.168.1.100" => "192.168.1.9") but the other code replaces the
> last digit ("192.168.1.100" => "192.168.1.109").
Uhmm, this is a possible alternative:
>>> s = " 192.168.1.100 "
>>> ".".join(s.strip().split(".")[:3])
On Oct 19, 5:47 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Pat a écrit :
>
> > I have a regexp in Perl that converts the last digit of an ip address to
> > '9'. This is a very particular case so I don't want to go off on a
> > tangent of IP octets.
>
> > ( my $s = $str ) =~ s/((\d+\.){
Pat a écrit :
I have a regexp in Perl that converts the last digit of an ip address to
'9'. This is a very particular case so I don't want to go off on a
tangent of IP octets.
( my $s = $str ) =~ s/((\d+\.){3})\d+/${1}9/ ;
While I can do this in Python which accomplishes the same thing:
i