1

I have a huge Json file containing objects of the form:

{ "country" : "UK",  "city" : "London"  }

I want to limit the number of instances for each "country". Can I do this using regex? I want to remove the whole block of object that contains "UK". I tried something like ^{.*"UK".*}, (starts with { contains "UK" ends with },) But this is wrong and I can't figure out the correct way. Any help would be appreciated.

1 Answer 1

4

In general, you should not be using regex alone to handle JSON content, even less so if that JSON be nested. If your JSON is always single level as you wrote above, then the following pattern might work:

\{[^}]*"UK"[^}]*\}

Replace the above by nothing, and do the find/replace in regex mode.

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Yes I was waiting for 8 minutes to pass, as it doesn't let me mark earlier!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.