【发布时间】:2019-01-13 09:00:11
【问题描述】:
我们正在使用 String 的 replaceAll 方法,我们不能替换任何字符串中的 {。 我们的例子:
试过了:
"some { string".replaceAll("{", "other string");
错误如下:
java.util.regex.PatternSyntaxException: 发生非法重复
欢迎任何想法!也许有解决方法?!
【问题讨论】:
-
你需要逃脱它
\{应该做的工作 -
您可能需要转义字符
{。试试.replaceAll("\\{", "other string"); -
除非您尝试使用正则表达式,否则您应该使用
replace,而不是replaceAll。
标签: java string methods replaceall