regexhelper
Test a pattern. Copy a ready-made one. No signup.

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.

Use it in your code

Python
import re
text = "NYC 40.7128,-74.0060 and London 51.5074, -0.1278. Not a pair: 200.0,999.0 is out of range (regex checks format, not bounds)."
pattern = r'''[-+]?\d{1,2}(?:\.\d+)?,\s*[-+]?\d{1,3}(?:\.\d+)?'''
for m in re.finditer(pattern, text):
    print(m.group())
JavaScript
const text = "NYC 40.7128,-74.0060 and London 51.5074, -0.1278. Not a pair: 200.0,999.0 is out of range (regex checks format, not bounds).";
const re = new RegExp(String.raw`[-+]?\d{1,2}(?:\.\d+)?,\s*[-+]?\d{1,3}(?:\.\d+)?`, "g");
console.log(text.match(re));

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.