Reputation: 3
For example I have this json:
{"a":"some value", "b":"some value", "c": "some ,\" value"}
I need to get:
"a":"some value" and "b":"some value" and "c": "some ," value"
I have ended with this regex (,)(?=(?:[^\"]|\"[^\"]*\")*$)
, but this doesn't work with third key value pair.
Upvotes: 0
Views: 480
Reputation: 20737
If you really must do this with regex then you can try:
(".*?(?<!\\)")\s*:\s*(".*?(?<!\\)")
(".*?
- start a capture group and match an opening double-quote and lazily match zero or more of any char(?<!\\)
- make sure that a \
does not precede the closing double-quote")
- find a closing double-quote and close the capture group\s*:\s*
- match a colon :
surrounded by optional whitespace(".*?(?<!\\)")
- see bullet points 1 through 3https://regex101.com/r/25qa84/1
Upvotes: 1