import re
regex = re.compile(r"([+-])?(\d\d)\*(?:([0-5]\d)'(?:((?:[0-5]\d)(?:\.\d+)?))?\")?([NS])?\/([+-])?([01]\d\d)\*([0-5]\d)'(?:(?:((?:[0-5]\d)(?:\.\d+)?))?\")?([EW])?\s")
test_str = ("7532N/10458W\n"
"7532/10458\n"
"753257/1045843\n"
"753257N/1045843E\n"
"753257.1/1045843.2 \n"
"753257.1N/1045843.2E\n"
"75:32N/104:58W\n"
"75:32/104:58\n"
"75:32:57/104:58:43\n"
"75:32:57N/104:58:43E\n"
"75:32:57.1/104:58:43.2\n"
"75:32:57.1N/104:58:43.2E\n\n\n\n"
"75*32/10458\n"
"75*32'57\"N/104*58'43\"E\n"
"75*32'57.1\"/104*58'43.2\"\n"
"75*32'57.1\"N/104*58'43.2\"E \n\n"
"75:32/10458\n"
"75:3257N/104:58:43E\n"
"75:32:57.1/104:5843.2\n"
"75:32:57.1N/1045843.2E \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