Hi guys i have a a string like this
String main = "Sandy \"children\":[]"
String foo = "\"children\":[]";
main = main.replaceAll(foo, "");
If I want to replace the whole foo in main with a single character “” then what regex I need to use?
I ll be having a json data like this i need to replace all the empty children object
{"data" : "Search engines",
"children":[ {
"data":"Yahoo","children":[{"data":"1","children":[{}]}]},
{"data":"Bing","children":[{"data":"2","children":[]}]},{"data":"Bing2"},{"data":"Bing3"},{"data":"Bing4"},{"data":"Bing5"},{"data":"Bing6"},{"data":"Bing7"},{"data":"Bing34"}]
}
Okay, now you’ve given more information, I would thoroughly recommend not using regular expressions for this. Parse the JSON and use the DOM representation of it instead. Otherwise there are bound to be ways of fooling whatever you use. Text representations like this are simply not a good match for regular expressions IMO.
(Original answer…)
It’s not clear why you’re using
replaceAlland regular expressions in the first place.I suspect you just want:
That will treat
fooas a normal string, not a regular expression. Unless you really want to use a regular expression, usereplaceinstead ofreplaceAll.