Regex replacement operation

Peter Abel p-abel at t-online.de
Thu Jan 16 16:32:22 EST 2003


S O R R Y ! !

I got the wrong order.
This one is better:
>> format=lambda match:'%04d-%02d-%02d'%(int(match.group(3)),int(match.group(2)),int(match.group(1)))
>>> re.sub(r'(\d+)-(\d+)-(\d+)',format,s)
'Today is 2003-01-16 or 2003-01-16. New Year was 2003-01-01,
reportedly.'
>>>




More information about the Python-list mailing list