import re
regex = re.compile(r"-?0+\.(0)+\b|\.0+\b|\b0+(?=\.\d*[1-9])|\b0+(?=[1-9]\d*\.)|(\.\d*?)0+\b")
test_str = ("00.00\n"
"00002.0\n"
"3.00\n"
"-4.0\n"
"0.00\n"
"-0.00\n"
"0.03\n"
"2.01\n"
"0.001\n"
"-0.03\n"
"101\n"
"0.001\n"
"-0.03\n"
".50\n"
"00.00\n"
"11.000000")
subst = "$1$2"
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