regexp in Python (from Perl)

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Oct 20 01:23:27 CEST 2008


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]) + ".9"
'192.168.1.9'

Bye,
bearophile



More information about the Python-list mailing list