With a string like so:
3 SOME STRING (remove me) 6 SOME OTHER STRING (also remove me!) 8 THIRD STRING (and me)
with the goal to strip away anything in parentheses and having the string turned into:
3 SOME STRING 6 SOME OTHER STRING 8 THIRD STRING
My best effort so far has been:
private String removeAnythingInParentheses(String input) {
return Pattern.compile("\\(.*\\)").matcher(input).replaceAll("").trim();
}
This however replaces too much of my string and leaves me with (I guess it matches the first parentheses to the very last in the string):
3 SOME STRING
I am sure there are some nifty features of Pattern and Matcher that I could use but I cannot figure them out...