Regex to match specific, multiline object in JSON list -


i work json lists can following:

 [     {       "accesstype": "*",       "principaltype": "role",       "principalid": "$unauthenticated",       "permission": "deny"     },     {       "accesstype": "*",       "principaltype": "role",       "principalid": "$everyone",       "permission": "deny"     },     {       "accesstype": "*",       "principaltype": "role",       "principalid": "$owner",       "permission": "allow"     }   ] 

what proper way write regex correctly extracts list item contains word $everyone? need extract entire object, correct result should be:

   {      "accesstype": "*",      "principaltype": "role",      "principalid": "$everyone",      "permission": "deny"    } 

i have tried \{(?s).*everyone(?s).*\}, match first , last opening , closing curly bracket in list, in between.

for one-off task of search , replace in ide:

\{[^}]*?everyone[^}]*\} 

if need $, use either:

\{[^}]*?\$everyone[^}]*\} \{[^}]*?[$]everyone[^}]*\} 

instead of (?s).* allows in between { , everyone , between everyone , }, restrict [^}]*?, disallows } in "free" part.

a lot of assumptions made in regex, don't use in general case.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -