import re
regex = re.compile(r"^(\-{0,1})(?:(?:0*)(\d+))?((?:\.)(?:\d*?))?0*$", flags=re.MULTILINE)
test_str = ("-0.002506000\n"
"1\n"
"01\n"
"10\n"
"1.25\n"
"01.250\n"
"0\n"
"0002345000\n"
"0.25\n"
"0.50\n"
"0.5\n"
"0.75000\n"
"1000\n"
"0001.111\n"
"0001.5\n"
".25\n"
"01234\n"
"-00.1\n"
".2500\n"
".0256\n"
"-.010")
subst = "$1$2$3"
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