I have the following code snippet:
Pattern patternOfSlashContainingBackSlash=Pattern.compile("\\/");
Pattern patternOfSlashNotContainingBackSlash=Pattern.compile("/");
String slash = "/";
Matcher matcherOfSlashContainingBackSlash = patternOfSlashContainingBackSlash.matcher(slash);
Matcher matcherOfSlashNotContainingBackSlash = patternOfSlashNotContainingBackSlash.matcher(slash);
//both patterns match the slash
System.out.println(matcherOfSlashContainingBackSlash.matches());
System.out.println(matcherOfSlashNotContainingBackSlash.matches());
My questions:
What is the difference (from Java perspective) between the two patterns, or is there any difference?
Is the '/' character just a plain character for regex(not a special character like ']' is) ,from Java perspective?
The java version on which I run this is 1.8
This question is different from the others, since it makes it clear that the patterns "\\/" and "/" are the same for Java programming language.
Thank you very much!