Regex how to get groups within json expression -
say have following json:
{"myperson":{"firstname":"first","lastname":"last","where":{"street":"street","number":15}},"anothercomplexobject":{"another":"yes","me":"true"},"count":1,"start":2}
i remove starting {
, ending }
, get:
"myperson":{"firstname":"first","lastname":"last","where":{"street":"street","number":15}},"anothercomplexobject":{"another":"yes","me":"true"},"count":1,"start":2
now, regex use "complex objects" out, example in json want these 2 results:
{"firstname":"first","lastname":"last","where":{"street":"street","number":15}} {"another":"yes","me":"true"}
the closest i've came solution regex {[^}]*}
1 fails select }
in "number":15
result.
# string # "myperson":{"firstname":"first","lastname":"last","where":{"street":"street","number":15}},"anothercomplexobject":{"another":"yes","me":"true"},"count":1,"start":2 /({[^}]+}})/ # http://rubular.com/r/rupven9yzo # match groups # 1. {"firstname":"first","lastname":"last","where":{"street":"street","number":15}} /({[^}]+})/ # http://rubular.com/r/h5faoh18c8 # match groups # match 1 # 1. {"firstname":"first","lastname":"last","where":{"street":"street","number":15} # match 2 # 1. {"another":"yes","me":"true"} /({[^}]+}})[^{]+({[^}]+})/ # http://rubular.com/r/zmcyjvor1y # match groups # 1. {"firstname":"first","lastname":"last","where":{"street":"street","number":15}} # 2. {"another":"yes","me":"true"} # string # {"myperson":{"firstname":"first","lastname":"last","where":{"street":"street","number":15}},"anothercomplexobject":{"another":"yes","me":"true"},"count":1,"start":2} /[^{]+({[^}]+}})[^{]+({[^}]+})/ # http://rubular.com/r/qcxn1rk9ka # match groups # 1. {"firstname":"first","lastname":"last","where":{"street":"street","number":15}} # 2. {"another":"yes","me":"true"}
Comments
Post a Comment