title: java regular expression to match file path
body: <p>I was trying out to create a regular expression to match file path in java like</p>
  <blockquote>
  <p>C:\abc\def\ghi\abc.txt</p>
  </blockquote>
  <p>I tried this <code>([a-zA-Z]:)?(\\[a-zA-Z0-9_-]+)+\\?</code> , like following code</p>
  <pre><code>import java.util.regex.Pattern;
  
    public class RETester {
  
  public static void main(String arhs[]){
  
      String regularExpression = &quot;([a-zA-Z]:)?(\\[a-zA-Z0-9_-]+)+\\?&quot;;
  
      String path = &quot;D:\\directoryname\\testing\\abc.txt&quot;;
  
      Pattern pattern = Pattern.compile(regularExpression);
  
      boolean isMatched = Pattern.matches(regularExpression,path);
      System.out.println(path);
      System.out.println(pattern.pattern());
      System.out.println(isMatched);
  
  }
  
  }
  </code></pre>
  <p>However it's always giving me , false as result .</p>