Re: regexp in Python (from Perl)

2008-10-24 Thread Pat
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+$

Re: regexp in Python (from Perl)

2008-10-20 Thread Bruno Desthuilliers
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

Re: regexp in Python (from Perl)

2008-10-20 Thread Pat
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

Re: regexp in Python (from Perl)

2008-10-20 Thread Bruno Desthuilliers
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"

Re: regexp in Python (from Perl)

2008-10-19 Thread bearophileHUGS
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])

Re: regexp in Python (from Perl)

2008-10-19 Thread MRAB
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+\.){

Re: regexp in Python (from Perl)

2008-10-19 Thread Bruno Desthuilliers
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