Regex to Match Latitude and Longitude
Copy the pattern, paste text below, and watch it highlight every coordinate pair. Below the tester: how the signed decimals are matched and their range limits.
What this pattern matches
This matches a decimal coordinate pair: a latitude, a comma, and a longitude, each optionally signed and with an optional fractional part.
How it works, part by part
[-+]?\d{1,2}(?:\.\d+)? — latitude: optional sign, one or two digits, optional decimals.
,\s* — the comma and any spaces between the two values.
[-+]?\d{1,3}(?:\.\d+)? — longitude: optional sign, one to three digits, optional decimals.
Format, not range
This checks the shape of a coordinate, not that latitude is within ±90 or longitude within ±180. Add a numeric range check in code if you need valid bounds.
FAQ
Does it enforce the -90..90 and -180..180 ranges?
No. Regex checks the number format only. Validate the actual ranges in code.
Does it handle degrees-minutes-seconds like 40°42'46"N?
No. This matches decimal degrees only. DMS notation needs a different pattern.