Skip to content

Instantly share code, notes, and snippets.

@jklmli
Created June 6, 2011 05:24
Show Gist options
  • Save jklmli/1009773 to your computer and use it in GitHub Desktop.
Save jklmli/1009773 to your computer and use it in GitHub Desktop.
zerofillstr.py
#!/usr/bin/env python
def zeroFillStr(inputString, numOfZeros):
# for clarity, used str concat instead of str formatting
return re.sub( '\d+',
lambda matchObj:
('%0' + str(numOfZeros) + 'i') % int(matchObj.group(0)),
inputString )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment