I looked at a stack overflow which gave me this regex- str.replaceAll("\\(^()*\\)", "");
but when I ran it, it didn't actually do anything.
so how do I remove from a given string any section which is within a Parentheses including the Parentheses?
also: Other than parentheses only letters and spaces can occur in the string. Don't worry about other brackets like "[]" and "{}" as these are not included, I don't want to touch "[]" and "{}" if they do appear. I only want to remove the Parentheses and the contents inside the Parentheses. help would be appreciated.
this also includes multiple parentheses and nested parentheses.
public static String removeParentheses(final String str) {
str.replaceAll("\\(^()*\\)", "");
System.out.println(str);
return str; // your code here
}
public static void main(String[] args) {
String str= "example(unwanted thing)example";
removeParentheses(str);
}
```
expected result is "exampleexample" but actual result was: "example(unwanted thing)example" which is not what I wanted.
I already searched stack overflow for help and found one place but it didn't help me.
help would be appreciated.