java - replaceAll() returns PatternSyntaxException

270 views Asked by At

I have this code :

    buffer = buffer.replaceAll("(","");

That is returning java.util.regex.PatternSyntaxException I don't know why. Help, please.

1

There are 1 answers

3
Andrew Tobilko On

Replace replaceAll("(","") with replaceAll("\\(", ""). ( is a special character, you should paste \\ before each of \.[]{}()*+-?^$|.

"sta(c(k(overfl(ow".replaceAll("\\(", "") -> "stackoverflow"