java - Regex to match nested json objects -


i'm implementing kind of parser , need locate , deserialize json object embedded other semi-structured data. used regexp:

\\{\\s*title.*?\\} 

to locate object

{title:'title'} 

but doesn't work nested objects because expression matches first found closing curly bracket. for

{title:'title',{data:'data'}} 

it matches

{title:'title',{data:'data'} 

so string becomes invalid deserialization. understand there's greedy business coming account i'm not familiar regexps. please me extend expression consume available closing curly brackets.

update:

to clear, attempt extract json data semi-structured data html+js embedded json. i'm using gson java lib parse extracted json.

as others have suggested, full-blown json parser way go. if want match key-value pairs in simple examples have above, use:

(?<=\{)\s*[^{]*?(?=[\},]) 

for input string

{title:'title',  {data:'data', {foo: 'bar'}}} 

this matches:

 1. title:'title'  2. data:'data'  3. foo: 'bar' 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -