I would like to add a certain number of leading zeroes (say up to 3) to all numbers of a string. For example:
Input: /2009/5/song 01 of 12
/2009/5/song 01 of 12
Outpu
Another approach:
>>> x '/2009/5/song 01 of 12' >>> ''.join([i.isdigit() and i.zfill(4) or i for i in re.split("(?>>
Or:
>>> x '/2009/5/song 01 of 12' >>> r=re.split("(?>> ''.join(a+b.zfill(4) for a,b in zip(r[::2],r[1::2])) '/2009/0005/song 0001 of 0012'