Regex replacement operation
David K. Trudgett
dkt at registriesltd.com.au
Fri Jan 17 00:19:39 CET 2003
On Thursday 2003-01-16 at 13:32:22 -0800, Peter Abel wrote:
> 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,
I knew what you meant! Thanks again.
More information about the Python-list