Question

I have a string like '''Coffee''' is a [[Drip brew|brewed]] [[beverage]] prepared from the roasted seeds of several species of an evergreen. I need to replace each [[something]] simply with something and if the there is more than one "phrase" such as [[Drip brew|brewed]], I would like to replace that set with the last (not necessarily second) phrase such as brewed in this example. Is there a clean way to do this using RegEx? I am trying to clean up some JSON from Wikipedia for some esoteric purposes.

Was it helpful?

Solution

string.replaceAll("\\[\\[([^]]*[|])?([^]]*?)\\]\\]", "$2");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top