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
  • 597
  • 3
  • 12
  • 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
  • 182,639
  • 35
  • 285
  • 343