java 反斜杠转义

时间:2022-12-06 14:45:38

代码如下:

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  转义代码