【发布时间】:2012-09-21 13:45:51
【问题描述】:
public static String template = "$A$B"
public static void somemethod() {
template.replaceAll(Matcher.quoteReplacement("$")+"A", "A");
template.replaceAll(Matcher.quoteReplacement("$")+"B", "B");
//throws java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3
template.replaceAll("\\$A", "A");
template.replaceAll("\\$B", "B");
//the same behavior
template.replace("$A", "A");
template.replace("$B", "B");
//template is still "$A$B"
}
我不明白。我使用了所有可以在互联网上找到的替换方法,包括我能找到的所有堆栈溢出。我什至试过\u0024!怎么了?
【问题讨论】:
标签: java regex string replace dollar-sign