RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find DMS Coordinates
Expression
(-?(90[ :°d]*00[ :\'\'m]*00(\.0+)?|[0-8][0-9][ :°d]*[0-5][0-9][ :\'\'m]*[0-5][0-9](\.\d+)?)[ :\?\"s]*(N|n|S|s)?)[ ,]*(-?(180[ :°d]*00[ :\'\'m]*00(\.0+)?|(1[0-7][0-9]|0[0-9][0-9])[ :°d]*[0-5][0-9][ :\'\'m]*[0-5][0-9](\.\d+)?)[ :\?\"s]*(E|e|W|w)?)
Description
Latitude and Longitude in Degrees Minutes Seconds (DMS) zero padded, separated by spaces or : or (d, m, s) or (°, ', ") or run together and followed by cardinal direction initial (N,S,E,W) Longitude Degree range: -180 to 180 Latitude Degree range: -90 to 90 Minute range: 0 to 60 Second range: 0.00 to 60.00 Note: Only seconds can have decimals places. A decimal point with no trailing digits is invalid.
Matches
40:26:46N,079:56:55W | 40°26′47″N 079°58′36″W | 40d 26m 47s N 079d 58′ 36″ W | 90 00 00.0, 180 00 00.0 | 89 59 50.4141 S 090 29 20.4 E | 00 00 00.0, 000 00 00.0
Non-Matches
90 00 00.001 N 180 00 00.001 E | 9 00 00.00 N 79 00 00.00 E | 9 00 00.00, -79 00 00.00 | 90 61 50.4121 S 090 29 20.4 E | -90 48 50. N -090 29 20.4 E | 90 00 00. N, 180 00 00. E | 00 00 00., 000 00 00.
Author Rating: Not yet rated. David Jacobs
Source Self-built
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Correction to previous comment.
Name: Matthew Mattson
Date: 11/12/2014 1:16:56 AM
Comment:
Sorry, had a duplicate parenthesis for group 17 & 18. And capture plus signs along with negative signs. By the way, though this site is great as a library and testing, http://www.regexr.com is awesome too! (I'm not associated with http://www.regexr.com in any way, just use tools that I find.) (([+-]?)((90)[ :°d]*(00)[ :\'\′m]*(00(?:\.0+)?)|([0-8][0-9])[ :°d]*([0-5][0-9])[ :\'\′m]*([0-5][0-9](?:\.\d+)?))[ :\?\"\″s]*(N|n|S|s)?)[ ,]*(([+-]?)((180)[ :°d]*(00)[ :\'\′m]*(00(?:\.0+)?)|(1[0-7][0-9]|0[0-9][0-9])[ :°d]*([0-5][0-9])[ :\'\′m]*([0-5][0-9](?:\.\d+)?))[ :\?\"\″s]*(E|e|W|w)?) More Matches: 40°26′47″N 079 ° 58 ′ 36 ″ W | 40d 26m 47s N 179d 58′ 36″ W | +90 00 00.0, -180 00 00.0 | -90 00 00.0, +180 00 00.0


Title: Capture each piece separately.
Name: Matthew Mattson
Date: 11/12/2014 1:00:33 AM
Comment:
David, thank you so much, this is an excellent regex! I've taken your work and added a few capturing and non-capturing parentheses so each piece of the coordinate can be captured for manipulation. ((-?)((90)[ :°d]*(00)[ :\'\′m]*(00(?:\.0+)?)|([0-8][0-9])[ :°d]*([0-5][0-9])[ :\'\′m]*([0-5][0-9](?:\.\d+)?))[ :\?\"\″s]*(N|n|S|s)?)[ ,]*((-?)((180)[ :°d]*(00)[ :\'\′m]*(00(?:\.0+)?)|((1[0-7][0-9]|0[0-9][0-9]))[ :°d]*([0-5][0-9])[ :\'\′m]*([0-5][0-9](?:\.\d+)?))[ :\?\"\″s]*(E|e|W|w)?)


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials