开发者

Match negative and positive decimals?

开发者 https://www.devze.com 2023-02-05 07:19 出处:网络
I\'m trying to match positive开发者_JAVA技巧 and negative numbers inbetween two tags using regex, the positive numbers return fine but the negative ones do not match. I am using:

I'm trying to match positive开发者_JAVA技巧 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消