用于匹配纬度/经度坐标的正则表达式? [英] Regular expression for matching latitude/longitude coordinates?

查看:22
本文介绍了用于匹配纬度/经度坐标的正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个正则表达式来匹配纬度/经度坐标.为了匹配双精度数,我使用了 (\-?\d+(\.\d+)?),并尝试将其组合成一个表达式:

I'm trying to create a regular expression for matching latitude/longitude coordinates. For matching a double-precision number I've used (\-?\d+(\.\d+)?), and tried to combine that into a single expression:

^(\-?\d+(\.\d+)?),\w*(\-?\d+(\.\d+)?)$

我希望这会匹配一个双精度、一个逗号、也许是一些空格和另一个双精度,但它似乎不起作用.具体来说,它仅在没有空间时才有效,而不是一个或多个.我做错了什么?

I expected this to match a double, a comma, perhaps some space, and another double, but it doesn't seem to work. Specifically it only works if there's NO space, not one or more. What have I done wrong?

推荐答案

空格是 \s,而不是 \w

Whitespace is \s, not \w

^(-?\d+(\.\d+)?),\s*(-?\d+(\.\d+)?)$

看看是否有效

这篇关于用于匹配纬度/经度坐标的正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆