regex - regular expression to avoid complete match -


i want extract id , type of objects (e.g. regions , countries) available=true. used regular expression {"name":".+?","id":"(.+?)","type":"(.+?)","available":true.

i'm getting complete row starting name ...{other stuff in middle}... available =true includes other ids/names available=false well.

sample data below

{    "error":null,  "data":{      "airports":[],    "pocs":[],    "regions":[        {           "name":"central america",         "id":"l04305",         "type":"cruisearea",         "available":false,         "countries":"mexico",         "group":null      },      {           "name":"caribbean",         "id":"l04304",         "type":"cruisearea",         "available":false,         "countries":"st maarten,barbados,british virgin islands,st kitts , nevis,st vincent , grenadines,antigua",         "group":null      },      {           "name":"western mediterranean",         "id":"l34381",         "type":"cruisearea",         "available":true,         "countries":"spain",         "group":null      },      {           "name":"eastern mediterranean",         "id":"l34373",         "type":"cruisearea",         "available":false,         "countries":"greece,italy,slovenia,montenegro,croatia",         "group":null      },      {           "name":"north africa , middle east",         "id":"l04301",         "type":"cruisearea",         "available":false,         "countries":"morocco",         "group":null      },      {           "name":"fjords, iceland , arctic",         "id":"l34384",         "type":"cruisearea",         "available":true,         "countries":"norway",         "group":null      },      {           "name":"northern europe , uk",         "id":"l34383",         "type":"cruisearea",         "available":true,         "countries":"united kingdom",         "group":null      }   ],   "countries":[        {           "name":"spain",         "id":"esp",         "type":"country",         "available":true,         "countries":null,         "group":null      },      {           "name":"jamaica",         "id":"jam",         "type":"country",         "available":false,         "countries":null,         "group":null      },      {           "name":"greece",         "id":"grc",         "type":"country",         "available":false,         "countries":null,         "group":null      },      {           "name":"italy",         "id":"ita",         "type":"country",         "available":false,         "countries":null,         "group":null      },      {           "name":"turkey",         "id":"tur",         "type":"country",         "available":false,         "countries":null,         "group":null      },      {           "name":"barbados",         "id":"brb",         "type":"country",         "available":false,         "countries":null,         "group":null      },      {           "name":"mexico",         "id":"mex",         "type":"country",         "available":false,         "countries":null,         "group":null      },      {           "name":"israel",         "id":"isr",         "type":"country",         "available":false,         "countries":null,         "group":null      },      {           "name":"cuba",         "id":"cub",         "type":"country",         "available":false,         "countries":null,         "group":null      },      {           "name":"croatia",         "id":"hrv",         "type":"country",         "available":false,         "countries":null,         "group":null      }     ],     "itineraries":[],     "airportgroups":[]   },  "nomatch":false,  "durations":null,  "searcherror":null } 

the simplest solution (without total re-write) be

{"name":"[^"]*","id":"([^"]*)","type":"([^"]*)","available":true,[^{}]*} 

instead of scanning . - character newline - scan character { or } - [^{}].

see here @ regex101.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -