【发布时间】:2012-01-19 10:31:39
【问题描述】:
我有一个字符串,当我尝试运行 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 {
如何替换 "{" 的出现?
【问题讨论】:
标签: java regex string replaceall