regexp in Python (from Perl)
Pat
Pat at junk.com
Sun Oct 19 14:04:51 EDT 2008
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:
ip = ip[ :-1 ]
ip =+ '9'
I'm more interested, for my own edification in non-trivial cases, in how
one would convert the Perl RE to a Python RE that use groups. I am
somewhat familiar using the group method from the re package but I
wanted to know if there was a one-line solution.
Thank you.
More information about the Python-list
mailing list