Mar-02-2025, 05:34 PM
(This post was last modified: Mar-02-2025, 05:40 PM by Pedroski55.)
Maybe like this:
import regex coords = '45° 46\' 52" N 108° 30\' 14" W' # simple it up a bit, all those backstrokes are confusing string = coords.replace('°', ' degrees').replace('\'', ' minutes').replace('"', ' seconds') # regex for string e = regex.compile(r'(\d+)\s+degrees\s+(\d+)\s+minutes\s+(\d+)\s+seconds\s+([NSWE])\s+(\d+)\s+degrees\s+(\d+)\s+minutes\s+(\d+)\s+seconds\s+([NSWE])') # find what you want res = e.match(string) for e in res.groups(): print(e)
Output:45
46
52
N
108
30
14
W
I believe you can do the arithmetic.