0

I'm trying to select all of the lowest tier(in the "nest") possible values that are numbers, and not strings, in a nested json. This will include arrays and objects. Currently, im using this code

(?<=:)\s*([+-]?\d+(?:\.\d*(?:E-?\d+)?)?)\b\s*(?=(?:\{|,)\s*\"[^\"]*\":)

(which is mostly from this question) and it works, if it isn't the last value of an object, or in a list. My main problem is, that it can be fooled. for example, if i have these two "a":":1,", ":":akey-value pairs next to eachother, it sees the number 1 as a value, except that the actual value is ":1,". How can i make a foolproof system for this?

Im excpecting it to not select anything, that couldn't be an integer or a float. I would like to keep the middle part of my original regex, beacuse it also needs to work with scientific notations.

  • A hammer is a very good tool. But I wouldn't use it to put a screw in place. Regexes are versatile tools. But just because you _can_ use it instead of a JSON parser, doesn't mean you _should_ use it. Months down the road, do you believe someone will maintain the code you write? – J_H Dec 13 '22 at 05:35
  • Regex is basicly my only option. I can't you a json parser, as that would turn a scientific flotation into a regular float, which I do not want – user15555955 Dec 13 '22 at 05:38

0 Answers0