import re
regex = re.compile(r"(\d*\.\d+|\d+\.\d*)([eE][\+-]?\d+)?|\d+[eE][\+-]?\d+", flags=re.MULTILINE)
test_str = ("123.45\n"
"58.087\n"
"50.0\n"
"0.123\n"
"51.\n"
"1.\n"
".99\n"
".523\n"
".7\n"
"0.0\n"
"0.1\n"
"0.\n"
".0\n"
"0.1\n"
"0.01\n"
"1.1\n"
"1.01\n"
"10.1\n"
"10.01\n\n"
"1e1\n"
"1e0\n"
"1E-1\n"
"1e10\n"
"0e41\n"
"1.e12\n"
"1.5e9\n"
"1.0E-2\n"
".2E4\n"
".0E+8\n"
"0.e71\n\n"
"1.23e1\n"
"7.001e-2\n"
"1.234E+9\n"
"1.23e1\n"
"1.23e+1\n"
"1.23e-1\n\n"
"// Not handled well\n"
"12..\n"
"0..24E23\n"
"..5")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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