1

I'm trying to match positive and negative numbers inbetween two tags using regex, the positive numbers return fine but the negative ones do not match. I am using:

string value8 = (",\"lng\":\"(([^\"\\\\]|-\\\\.)*)\",");
Match[] lng = Regex.Matches(Text, value8)

to match against

"lng":"-104.845275878905880"

or similar, it can be positive or negative. When positive it matches the number but when negative, there are no matches.

user556396
  • 577
  • 3
  • 10
  • 26

1 Answers1

2

Unless I'm missing something, your regex looks a little more complex than it needs to be. You should be able to use something like this:

"\"lng\":\\\"(-?[0-9]*\\.?[0-9]*)\\\""

Incidentally, I removed the comma at the beginning of your expression, as that would prevent this pattern from matching your sample data.

Adam Robinson
  • 177,794
  • 32
  • 275
  • 339