Possible Duplicate:
Wrong output using replaceall
If I have string:
String test = "replace()thisquotes";
test = test.replaceAll("()", "");
the test result is still: test = "replace()thisquotes"
so () is not replaced.
Any ideas?
You don't need regex, so use:
test.replace("()", "")
As others have pointed out, you probably want to use String.replace in this case as you don't need regular expressions.
For reference however, when using String.replaceAll, the first argument (which is interpreted as a regular expression) needs to be quoted, preferably by using Pattern.quote:
String test = "replace()thisquotes";
test = test.replaceAll(Pattern.quote("()"), "");
// ^^^^^^^^^^^^^
System.out.println(test); // prints "replacethisquotes"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With