I was trying out to create a regular expression to match file path in java like
C:abcdefghiabc.txt
I tried this ([a-zA-Z]:)?(\[a-zA-Z0-9_-]+)+\?
, like following code
import java.util.regex.Pattern;
public class RETester {
public static void main(String arhs[]){
String regularExpression = "([a-zA-Z]:)?(\[a-zA-Z0-9_-]+)+\?";
String path = "D:\directoryname\testing\abc.txt";
Pattern pattern = Pattern.compile(regularExpression);
boolean isMatched = Pattern.matches(regularExpression,path);
System.out.println(path);
System.out.println(pattern.pattern());
System.out.println(isMatched);
}
}
However it's always giving me , false as result . Pls help me .
Thanks
See Question&Answers more detail:os