GPS Coordinates (Decimal Degrees — High Precision) Regex for Go
/^(-?(?:90(?:\.0{1,6})?|(?:[0-8][0-9]|[0-9])(?:\.[0-9]{1,8})?)),\s?(-?(?:180(?:\.0{1,6})?|(?:1[0-7][0-9]|[0-9]{1,2})(?:\.[0-9]{1,8})?))$/What this pattern does
This page provides a comprehensive, battle-tested regular expression for matching gps coordinates (decimal degrees — high precision), ported and verified for Go. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.
Go Implementation
// GPS Coordinates (Decimal Degrees — High Precision)
// ReDoS-safe | RegexVault — Identity & PII > Location PII
package validation
import "regexp"
var gpsCoordinatesDecimalDegreesHighPrecisionRe = regexp.MustCompile(`^(-?(?:90(?:\.0{1,6})?|(?:[0-8][0-9]|[0-9])(?:\.[0-9]{1,8})?)),\s?(-?(?:180(?:\.0{1,6})?|(?:1[0-7][0-9]|[0-9]{1,2})(?:\.[0-9]{1,8})?))$`)
func ValidateGpsCoordinatesDecimalDegreesHighPrecision(s string) bool {
return gpsCoordinatesDecimalDegreesHighPrecisionRe.MatchString(s)
}
// Example
// fmt.Println(ValidateGpsCoordinatesDecimalDegreesHighPrecision("1.3521,103.8198")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
1.3521,103.8198 | 91,0 |
51.5074,-0.1278 | -91,0 |
-33.8688,151.2093 | 0,181 |
0,0 | 0,-181 |
90.0,-180.0 | 1.3521,103.8198,50 |
When to use this pattern
This pattern is drawn from the Identity & PII > Location PII category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.
Common Pitfalls
GPS coordinate precision matters for privacy. Truncating to 2 decimal places (≈1km) is a common anonymization technique. Movement history (multiple GPS coordinates over time) constitutes location profiling — stricter treatment required.
Technical Notes
High-precision GPS (>4 decimal places) can identify a specific building or room. 4 decimal places ≈ 11m accuracy. 6 decimal places ≈ 0.1m. GPS coordinates of a home address or frequent location are personal data under GDPR.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern