re.sub('(\\d+)', lambda m: m.group(1).zfill(2), text)
re.sub('([a-z]+)(\\d+)', lambda m: m.group(1) + m.group(2).zfill(2), text)
using regular expression substitution command to insert leading zeros in front of numbers less than 10 in a string of filenames