代码如下:
public static void main(String[] args) {
String str = "\\'";
System.out.println("'");// '
System.out.println("\'");// '
System.out.println("\\'");// \' 因为第二个斜杠被转义了,注意被转义了就变成正常的字符了,不参与之后的转义
System.out.println("'".matches("'")); //true
System.out.println("'".matches("\'")); //true
System.out.println("'".matches("\\'"));//true
System.out.println("'".matches("\\\'"));//true
System.out.println("'".matches("\\\\'"));//false
System.out.println("\'".matches("\\'")); //true
System.out.println("\'".matches("\'")); //true
System.out.println("\\'".matches("\\\'")); //false
System.out.println("\\'".matches("\\\\'")); //true
}
如图1:
图1 转义代码