我想提取對象(如Regions和Countries)的id
和type
,其中available=true
。我用正則表達式{"name":".+?","id":"(.+?)","type":"(.+?)","available":true
。避免完全匹配的正則表達式
我得到一個從名稱開始的完整行... {other in the middle} ... available = true其中包括其他ID /名稱,即使在available=false
也是如此。下面
{
"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 and Nevis,St Vincent and the 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 And Middle East",
"id":"L04301",
"type":"CruiseArea",
"available":false,
"countries":"Morocco",
"group":null
},
{
"name":"Fjords, Iceland And Arctic",
"id":"L34384",
"type":"CruiseArea",
"available":true,
"countries":"Norway",
"group":null
},
{
"name":"Northern Europe And 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
}
使用[^「]''代替。+?' – hjpotter92
而是使用JSON解析器像https://github.com/stig/json-framework – hjpotter92
嗨..感謝..我得到了我想要的使用[^「] + – shett