I am trying to check if a chosen path is a valid path for my Java program. In order to be valid, it must match the path E:\test\(someFolderName)\
. The chosen folder can be deeper in that directory.
This is what I have tried:
String a = "E:\\test\\anotherFolder";
if (a.matches("E:\\\\btest\\b\\.*")) {
System.out.println("match");
}
I have also tried putting test
into []
but it did not work.
\b
would mark the beginning of a word boundary, and adding \b
again should close it, correct?
.*
would match any character 1 to infinite times.
So, is there a problem with the escaping? Or do I need to group it differently?