I have expression parser and I want to add json support so I need to match one of [
or {
any number of characters that may include paired []
and {}
and then ]
or }
.
So far I have ([[{])(.(?!\1))*[\]}]
it match [foo}
but I can live with that. Invalid json will be catch when json_decode return null.
I need to match JSON in strings like this:
{"foo":"bar"} == 20
[1,2,3,4] == 10
but also first JSON in those strings:
{"foo": "bar"}["foo"]
[1,[2],{"foo":"bar"},4][0]
{"foo": "bar"} == {"foo": "bar"}
So far I have regex like this ^([\[{](?>"(?:[^"]|\\")*"|[^\]}]|(?1))*[\]}])
: demo but it don't match:
[1,[2],{"foo":"bar"},4]