我有一个字符串,当我尝试运行replaceAll
方法时,出现了这个奇怪的错误:
String str = "something { } , op";
str = str.replaceAll("o", "\n"); // it works fine
str = str.replaceAll("{", "\n"); // does not work
但我遇到了一个奇怪的错误:
Exception in thread "main" java.util.regex.PatternSyntaxException:
Illegal repetition {
如何替换字符串中的 "{"
字符?
replace()
只是替换第一个实例。这就是我没有查看文档的下场! - Daniel Black