import re
regex = re.compile(r"^(?P<degrees>-?\d+)(?P<decimal_minutes>\d{2}.*)", flags=re.MULTILINE)
test_str = ("-7045.886002\n"
"7203.23423\n"
"11023.2343\n"
"-17323.2343\n")
subst = "\\g<degrees> \\g<decimal_minutes>"
result = regex.sub(subst, test_str)
if result:
print(result)
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