<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>[Lightstalkers] Regex for decimal coordinates</title>
    <link>http://www.lightstalkers.org/posts/regex-for-decimal-coordinates</link>
    <description>An entire Lightstalkers thread via RSS/XML.</description>
    <language>en-us</language>
    <item>
      <title>Regex for decimal coordinates</title>
      <description>Does anyone know how to write a regular expression that would validate decimal latitude and longitude? I stink at regex.</description>
      <pubDate>Wed, 12 Mar 2008 12:53:42 +0000</pubDate>
      <link>http://www.lightstalkers.org/posts/regex-for-decimal-coordinates</link>
    </item>
    <item>
      <title>Re: Regex for decimal coordinates</title>
      <description>ooh ooh, I was waiting for someone to ask about regex's! What flavor of regex? What are the parameters for lat/long ranges? (i guess I could look it up).
I'm doing a lot of regex's lately.</description>
      <pubDate>Mon, 17 Jan 2005 14:45:07 +0000</pubDate>
      <link>http://www.lightstalkers.org/posts/regex-for-decimal-coordinates#1243</link>
    </item>
    <item>
      <title>Re: Regex for decimal coordinates</title>
      <description>Holy cow, for real? I have to post more questions!

Ok, here are the valid ranges:

*Latitude: -90.0000 to 90.0000*

*Longitude: -180.0000 to 180.0000*

Not too bad, right?</description>
      <pubDate>Mon, 17 Jan 2005 14:58:14 +0000</pubDate>
      <link>http://www.lightstalkers.org/posts/regex-for-decimal-coordinates#1244</link>
    </item>
    <item>
      <title>Re: Regex for decimal coordinates</title>
      <description>quick questions:

a.) What are you programming in? (shell, perl, php, java. . .)
b.) Why regex instead of specifying a numerical range? (Depends on answer to the first question I guess)

I ask because regex can be overly complicated for values, but great for other text.

in the meantime, I'm working on it. . .</description>
      <pubDate>Tue, 18 Jan 2005 02:19:40 +0000</pubDate>
      <link>http://www.lightstalkers.org/posts/regex-for-decimal-coordinates#1254</link>
    </item>
    <item>
      <title>Re: Regex for decimal coordinates</title>
      <description>I'm coming from a UNIX/shell/Perl background, but this should apply to other regex applications as well.

Using egrep-style Extended Regular Expressions (ERE's):

first check that input is not null/blank
(shouldn't require regex)

check that input doesn't contain characters other than numbers, decimal points, and minus signs
regex:
[^0-9BACKSLASH.BACKSLASH-]+
(replace BACKSLASH with a you-know-what, this posting system don't like BACKSLASHES)

and then check for valid numeric format
regex:
[-]?[0-9]*[.]{0,1}[0-9]{0,4}

the above regex checks for (in this order): starts with exactly one or none minus sign(s), followed by a numeric string (or not), followed by exactly one decimal point or no decimal point, followed by a numeric string of length 0-4

some valid input:
-19.908
80.847
-180
1.0
0.0999
.0999
179.9999

for stricter formatting of the fractional decimal value, use:
[-]?[0-9]*[.]{0,1}[0-9]{4}

valid input:
.0999
-0.1234
-90.0000
179.9999

and then check for appropriate value range with greater than less than operators 
(shouldn't require regex)

Hope that helps.  Let me know if I'm way off.

For some more help, here is an awesome regex reference:
&quot;http://www.regular-expressions.info/&quot;:http://www.regular-expressions.info/

and an interactive regex tester (for javascript)
&quot;http://www.regular-expressions.info/javascriptexample.html&quot;:http://www.regular-expressions.info/javascriptexample.html

-kelly</description>
      <pubDate>Tue, 18 Jan 2005 04:07:15 +0000</pubDate>
      <link>http://www.lightstalkers.org/posts/regex-for-decimal-coordinates#1259</link>
    </item>
    <item>
      <title>Re: Regex for decimal coordinates</title>
      <description>Ah, this is excellent! Thank you so much Kelly; this is exactly the instruction I needed. Thanks to you &quot;the map&quot;:map.cfm?setshow=all is going to be much more populous from now on... :-)</description>
      <pubDate>Fri, 21 Jan 2005 16:53:44 +0000</pubDate>
      <link>http://www.lightstalkers.org/posts/regex-for-decimal-coordinates#1332</link>
    </item>
  </channel>
</rss>
