Novocaine Novocaine - 1 month ago 12
JSON Question

Wrap integers in quotes from json data

I created this question yesterday

I've since realised there are actually a few other bits of data that cause issues with the solutions I received. Hence, I thought it best to make a new question

Take the following example data;

"87",0000,0767,"078",0785,"0723",23487, "061 904 5284","17\/10\/2016","some.name.789@hotmail.com"


Using the accepted solution form above
(?<!")(\b\d+\b)(?!")


The date string ends up having the middle number in between the two
\/
wrapped, the number in quotes with spaces breaks as well as the email address.
The issues can be seen here: https://regex101.com/r/qVQYA7/6

My Solution

The following does seem to work for me, however it seems a bit messy. I have a feeling there's a much more succinct way to achieve the same result;

,(?<!("|\/|\\))(\b\d+\b)(?!("|\/|\\|( \d)))
Replace with
,"$2"


https://regex101.com/r/qVQYA7/5

EDIT:

@Federico this screenshot shows that spaces before or after commas breaks the replace;
enter image description here

Answer

By reading your both questions, what I understand is that you want to wrap in double quots some numbers that aren't, so for this I can come up with a simple regex like this:

(?<=,)(\d+)(?=,)

With the replacement string: "$1"

Working demo

enter image description here

Update: after you updated the question, here I put the update for the answer. You can use this regex instead:

(?<=,)\s*(\d+)\s*(?=,)