I would like to convert the coordinates displayed in Apple Maps as
38,89016° N, 1,22427° O
(German notation)
or
38.89016° N, 1.22427° E
(English notation)
into something like
38.89016, 1.22427
(Expected result)
but only if the user did enter a expression matching this pattern and not if the user enters something like an address or anything in the input field.
Therefore I would be using PHP preg_replace()
However I have difficulties building a matching regex and was wondering if someone found a solution to this already?
I already tried different regex variations on my own already, but they did not work anything like what I would expect, so I did not add them here.
I though have a regex to verify, the expected result is in the correct form which does work as expected, though I wasn’t able to modify it for the replacement:
/^[-+]?([1-8]?d(.d+)?|90(.0+)?),s*[-+]?(180(.0+)?|((1[0-7]d)|([1-9]?d))(.d+)?)$/