Created
June 6, 2011 05:24
-
-
Save jklmli/1009773 to your computer and use it in GitHub Desktop.
zerofillstr.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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