【发布时间】:2013-10-01 10:52:28
【问题描述】:
我在使用replaceFirst 时得到一个奇怪的ArrayOutOfBoundsException:
"this is an example string".replaceFirst("(^this )", "$1\\") // throws ArrayOutOfBoundsException
"this is an example string".replaceFirst("(^this )", "$1") // works fine
我正在尝试实现这个字符串:
"this \is an example string"
如果我尝试在替换字符串中放入转义的反斜杠,为什么会收到 ArrayOutOfBoundsException?如果它有所作为,Android 上就会发生这种情况
这是一个ideone 异常示例。
这里是 logcat 异常堆栈跟踪:
java.lang.ArrayIndexOutOfBoundsException: index=14 在 java.util.regex.Matcher.appendEvaluated(Matcher.java:149) 在 java.util.regex.Matcher.appendReplacement(Matcher.java:111) 在 java.util.regex.Matcher.replaceFirst(Matcher.java:304) 在 java.lang.String.replaceFirst(String.java:1793)
【问题讨论】: