tags:

views:

75

answers:

3

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?

+1  A: 

I believe you're using \w (word character) where you ought to be using \s (whitespace). Word characters typically consist of [A-Za-z0-9_], so that excludes your space, which then further fails to match on the optional minus sign or a digit.

theraccoonbear
+1  A: 

Whitespace is \s, not \w

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

See if this works

Eric C
Ah, a simple mistake! Thanks. :)
Jake Petroules