import re
regex = re.compile(r"(?<)\b0+([1-9])")
test_str = ("10/01/13 -> 10/1/13\n"
"10/10/13 -> no change\n"
"10/1/13 -> no change\n"
"01/10/13 -> 1/10/13\n"
"An amount of $10,001.02. Pretty expensive!\n"
"01.01.03")
subst = "$1"
result = regex.sub(subst, test_str)
if result:
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html