import re
regex = re.compile(r"^(\+ *|- *)?((?!0+)\d*?|(?!0{2,})\d*?\.(?!0+)\d*?)('|\")$|^(\+ *|- *)? *(?!0+)\d+?' *-? *(\d+?|\d*?\.\d*?)\"$|^((\+ *|- *)?((?!0+)|0 )\d*? *(?!0+)\d+?\/(?!0+)\d+?('|\"))$", flags=re.MULTILINE)
test_str = (" - \n"
" + \n"
"- x 20'-4\"\n"
"+ 20'\n"
"- 20'\n"
"20'3\"\n"
"20'-3\"\n"
"20' - 40\"\n"
"-20'-20\"\n"
"20'00\"\n"
"20.45\"\n"
"20.45'\n"
"00.45'\n"
"00.45\"\n"
"00\"\n"
"00'\n"
"+20' - 0.45\"\n"
" 20' - .45\"\n"
".20'-4\"\n"
"0.30'-4\"\n"
" 20'\n"
"20'P\n"
" 20\"\n"
"20\"P\n"
"0.20'\n"
".20'\n"
"a'\n"
"b\"\n"
"- 20 1/2'\n"
"+ 20 22/128\"\n"
"20 0/2\"\n"
"20 00/12'\n"
"-1/2\"\n"
"+ 1/2'\n"
"0/2\"\n"
"00/22\"\n"
"+ 01/2\"\n"
"23 00/30'\n"
"23 12/03'\n"
"23 02/20\"\n"
"0 2/3'\n"
"00 2/3'\n"
"- 11 2/3'\n"
"2 22'\n"
"2 22/03'\n"
"2 3/2\n"
"23 00/30\n"
"23 12/03\n"
"23 02/20\n"
"23/34\"\n"
"23/23.4\"\n"
"asf sf\"\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