import re
regex = re.compile(r"^(0|[1-9][0-9]*)(e-?(0|[1-9][0-9]*))?$", flags=re.MULTILINE)
test_str = ("0\n"
"1\n"
"-0\n"
"-1\n"
"+0\n"
"+1\n"
"01\n"
"-01\n"
"+01\n\n"
"2.3\n"
"-2.3\n"
"1.00\n"
"0.00\n"
"-0.00\n"
"00.00\n"
"-00.00\n"
"02.3\n"
".0\n"
".1\n"
"-.1\n"
"0.\n"
"1.\n"
"10.\n"
"2,3\n"
",0\n\n"
"0e0\n"
"2e5\n"
"-e10\n"
"-e-10\n"
"2.3e5\n"
"-2.3e5\n"
"2.3e-5\n"
"2.3e03\n"
"2.3e0\n"
"0.01e4\n"
".1e5\n"
"-.1e5\n"
"-.0e0\n"
"-0.0e10\n"
"2,3e5\n"
" \n"
".\n"
"-\n"
"-.\n"
"b1\n"
"1b\n"
"2-3\n"
"3.4.5\n"
"4.,6\n"
"1,.\n"
"e\n"
"-e\n"
"-.e\n"
".e4\n"
"1e2-2\n"
"e2.3\n"
"e2.3.4\n"
"-e10\n"
"1e.-\n"
"10e.\n"
"1\\n\n"
"1\\t\n"
"1 1\n"
"\\n\n"
"\\t\n")
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