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.' >>>