java 反斜杠转义

时间:2021-09-11 03:55:36

代码如下:

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:

java 反斜杠转义

图1  转义代码