简体   繁体   English

正则表达式匹配谷歌地图纬度

[英]Regex to match google map lat long

I am using google map and i need to update map using lat long and to verify that some doesn't put invalid data i want a regex which can test entered lat long 我正在使用谷歌地图,我需要使用经纬度来更新地图,并验证某些人不会放置无效数据,我想要一个可以测试输入经纬度的正则表达式

But now when i see there are three type of lat long as described here 但是现在当我看到这里有三种类型的经纬度

Google Map Lat Long Search Google Map Lat Long搜索

I made a regex for Decimal degrees (DDD) which is following 我为以下的Decimal degrees (DDD)作了正则表达式

^([-+]?\d{1,2}([.]\d+)?),\s*([-+]?\d{1,3}([.]\d+)?)$

But this regex doesn't fulfill 但是此正则表达式无法满足

Degrees, minutes and seconds (DMS): 41° 24' 12.1674", 2° 10' 26.508"

AND

Degrees and decimal minutes (DMM): 41 24.2028, 2 10.4418

So in simple i need regex to verify all these three types 所以简单地说,我需要正则表达式来验证所有这三种类型

You can add an OR operator | 您可以添加OR运算符|

^ anchor beginning ^锚开始
(?: start a non-capturing group (?:启动一个非捕获组
([-+]?\\d{1,2}([.]\\d+)?),\\s*([-+]?\\d{1,3}([.]\\d+)?) Your current regex. ([-+]?\\d{1,2}([.]\\d+)?),\\s*([-+]?\\d{1,3}([.]\\d+)?)正则表达式。
| OR 要么
Make one for degrees & minutes & seconds 度数,分度和秒数
| OR 要么
Make one for degrees and decimal minutes 将度数和小数分钟加一
) end non-capturing group )结束非捕获组
$ anchor end $锚端

Let me know if you have more questions on this. 如果您还有其他疑问,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM