This section contains regular expressions for converting plain-text geographical coordinates to {{ coord }} .
I had originally hoped to be able to combine all of this functionality into one gigantic, extremely awesome expression. I'm not sure if it's possible, but I've definitely given up. These do make sure that you enter valid coordinates, which I'm pleased with.
I originally just had them require the correct number of digits (up to two for latitude and up to three for longitude), but then you could still input something like 91° N, 181° W. Fixing that problem made me feel sufficiently spiffy that I could give up on my gigantic regex dream without much guilt.
Description
Use {{ coord }} on coordinates in degree format.
Find
\b(?<!\.)(90|[1-8]\d(?:\.\d+)?)°(?:\s| )*(N|S),?(?:\s| )*(180|(?:1[1-7]\d|\d{1,2})(?:\.\d+)?)°(?:\s| )*(W|E)\b
Replace with
{{coord|$1|$2|$3|$4}}
Regular expression?
Case sensitive?
Y
N
Text this regex should modify:
Intended result:
51°N 0°W
40.71° N, 74.0° W
51°N 0°W / 51°N -0°E / 51; -0
40°43′N 74°00′W / 40.71°N 74.0°W / 40.71; -74.0
Text this regex should not modify:
91°N 74°W
90.1° N, 74.0° W
51°N 181°W
51° N, 180.1° W
Description
Use {{ coord }} on coordinates in degrees-minutes format
Find
\b(?<!\.)([1-8]\d)°(?:\s| )*([1-5]?\d)(\.\d+)?['’′](?:\s| )*(N|S),?(?:\s| )*((?:1[1-7]\d|\d{1,2})(?:\.\d+)?)°(?:\s| )*([1-5]?\d)(\.\d+)?['’′](?:\s| )*(W|E)\b
Replace with
{{coord|$1|$2$3|$4|$5|$6$7|$8}}
Regular expression?
Case sensitive?
Y
N
Text this regex should modify:
Intended result:
51°5'N 0°7'W
40° 19.3′N, 74° 50.1234′ W
51°5′N 0°7′W / 51.083°N 0.117°W / 51.083; -0.117
40°19.3′N 74°50.1234′W / 40.3217°N 74.8353900°W / 40.3217; -74.8353900
Text this regex should not modify:
51°N 0°W
40.71°, -74.0°
90° 3' N, 74° 19' W
51° 3' N, 180° 19' W
51°61'N 0°7'W
40° 19.3′N, 74° 60.1234′ W
Description
Use {{ coord }} on coordinates in degrees-minutes-seconds format
Find
\b(?<!\.)([1-8]\d)°(?:\s| )*([1-5]?\d)['’′](?:\s| )*([1-5]?\d)(\.\d+)?["”″](?:\s| )*(N|S),?(?:\s| )*((?:1[1-7]\d|\d{1,2})(?:\.\d+)?)°(?:\s| )*([1-5]?\d)['’′](?:\s| )*([1-5]?\d)(\.\d+)?["”″](?:\s| )*(W|E)\b
Replace with
{{coord|$1|$2|$3$4|$5|$6|$7|$8$9|$10}}
Regular expression?
Case sensitive?
Y
N
Text this regex should modify:
Intended result:
51°5'11"N 0°7'19"W
40° 44' 19.3"N, 74° 16' 50.1234" W
51°5′11″N 0°7′19″W / 51.08639°N 0.12194°W / 51.08639; -0.12194
40°44′19.3″N 74°16′50.1234″W / 40.738694°N 74.280589833°W / 40.738694; -74.280589833
Text this regex should not modify:
51°N 0°W
40.71°, -74.0°
40° 19.3′N, 74° 50.1234′ W
51°16'61"N 0°7'33"W
40° 46' 19.3"N, 74° 11' 60.1234" W