User:TomTheHand/Unit tests for AWB regexes/Geographical coordinates
Appearance
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.
Convert coordinates in degree format
[edit]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: |
|
|
Text this regex should not modify: | |
|
Convert coordinates in fully-decimal degree format
[edit]Description | |
---|---|
Use {{coord}} on coordinates in fully-decimal degree format | |
Find | |
(?<!\.)(-)?\b(90|[1-8]\d(?:\.\d+)?)°,?(?:\s| )*(-)?(180|(?:1[1-7]\d|\d{1,2})(?:\.\d+)?)° | |
Replace with | |
{{coord|$1$2|$3$4}} | |
Regular expression? | Case sensitive? |
Y | N |
Text this regex should modify: | Intended result: |
|
|
Text this regex should not modify: | |
|
Convert coordinates in degrees-minutes format
[edit]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: |
|
|
Text this regex should not modify: | |
|
Convert coordinates in degrees-minutes-seconds format
[edit]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: |
|
|
Text this regex should not modify: | |
|