import java.io.*;
class Test{
public static void main(String[] args) throws Exception{
String s = "abc300";
System.out.println(s.replaceAll("abc", "$ ")); //line 1 throws Exception
System.out.println(s.replaceAll("abc", "cost ")); //OK!
System.out.println(s.replaceAll("abc", "\$ ")); //compile error
System.out.println(s.replaceAll("abc", "\\$ ")); //OK!
}
}/*
Exception in thread "main" java.lang.IllegalArgumentException: Illegal group ref
erence
        at java.util.regex.Matcher.appendReplacement(Matcher.java:706)
        at java.util.regex.Matcher.replaceAll(Matcher.java:806)
        at java.lang.String.replaceAll(String.java:2028)
        at Test.main(tmp.java:5)
 */若"$",则抛出异常
若"\$",则编译错误,但是想在字符串中包含",用的是single backslash——"\""
若"\\$",OK
谁能说一下到底什么时候是single backslash \
什么时候是double backslash \\