Regular expression for longitude latitude pairs

I draw a line on a google map, than create a line, for example:

(- 25.368819800291383,130.55809472656256) (- 25.507716386730266,131.05797265625006) (-24.89637614190406,131.49193261718756) (- 24.582068950590272,130.31090234375006)

the first value is latitude, the second is longitude. I assign a hidden field value to this line so that I can get it on the server.

How to get latitude and longitude numbers?

I have tried

 Match match = Regex.Match(points, @"(^(0|(-(((0|[1-9]\d*)\.\d+)|([1-9]\d*))))$,^(0|(-(((0|[1-9]\d*)\.\d+)|([1-9]\d*))))$)*", RegexOptions.IgnoreCase);
+3
source share
3 answers

Try

\((?<lat>[-\d.]+),(?<long>[-\d.]+)\)

I like to use named groups here. To use only latitudes, use

    Regex regexObj = new Regex(@"\((?<lat>[-\d.]+),(?<long>[-\d.]+)\)");
    Match matchResult = regexObj.Match(subjectString);
    while (matchResult.Success) {
        Console.WriteLine(matchResult.Groups["lat"].Value));
        matchResult = matchResult.NextMatch();
+1
source

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

.

+2

:

Match match = Regex.Match(points, @"(-?\d+\.\d+)+", RegexOptions.IgnoreCase);

8 , =

Match match = Regex.Match(points, @"((-?\d+\.\d+)+,?){2}", RegexOptions.IgnoreCase);

4 , ,

0

All Articles