以下简单代码失败(我希望结果为"abc$1%s"
):
"\\$[0-9]+".r
.replaceAllIn(
"abc$1", {
mtch =>
mtch.toString() + "%s"
})
用
No group 1
java.lang.IndexOutOfBoundsException: No group 1
我已正确转义美元符号并避免所有前瞻/回顾控制字符,为什么它仍然失败?
答案 0 :(得分:3)
The group error means you don't have a parenthesis delimited group defined.
Something like "(\\$[0-9]+)"
would define your whole regex as a group.