Java String ReplaceAll method giving illegal repetition error?
问题 I have a string and when I try to run the replaceAll method, I am getting this strange error: String str = "something { } , op"; str = str.replaceAll("o", "\n"); // it works fine str = str.replaceAll("{", "\n"); // does not work and i get a strange error: Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition { How can I replace the occurrences of "{" ? 回答1: A { is a regex meta-character used for range repetitions as {min,max} . To match a literal { you need to