import re
regex = re.compile(r"^((?!-0?(\.0+)?(e|$))-?(0|[1-9]\d*)?(\.\d+)?(?<=\d)(e-?(0|[1-9]\d*))?|0x[0-9a-f]+)$", flags=re.MULTILINE | re.IGNORECASE)
test_str = ("3\n"
"999\n"
"-3\n"
"0\n"
"0.0\n"
"1.0\n"
"0.1\n"
".01\n"
"-0.0000000000000000000000000000000001\n"
"2e3\n"
"-2e3\n"
"2e-3\n"
"-2e-3\n"
"1.0e0\n"
"0.1e1\n"
".01e-1\n"
"-9.1e3\n"
"-9.1e-3\n"
"9E5\n"
"0e-11\n"
"0xff\n"
"0XFF\n"
"0x0\n"
"0xfe3\n"
"0e0\n"
".0e-0\n"
".0e5\n"
".0e-5\n"
"0.0e0\n"
"0.0e123\n"
"0.0e-123\n"
"-0\n"
"-0.0\n"
"-0.0000000000000000000000000000000000\n"
"-.0\n"
"-.0000000000000000000000000000000000\n"
"1xff\n"
"0x\n"
"0x0fg3\n"
"0xf4.\n"
".0xf\n"
"0xfe-3\n"
"-0xff\n"
"0.0xff\n"
"0xff.1\n"
"1e-\n"
"e89\n"
".e3\n"
"001\n"
"-00.2\n"
"6.\n\n"
"f\n"
" -1\n"
"--1\n"
"-.1\n"
"2-\n"
".-1")
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