title: Regular expression to validate windows and linux path with extension
body: <p>I am trying to write a function which will validate weather the given path is valid in Linux/Windows with file extension.</p>
  
  <p>ex: </p>
  
  <p>Windows path: D:\DATA\My_Project\01_07_03_061418738709443.doc<br>
  Linux path: /source_data/files/08_05_09_1418738709443.pdf</p>
  
  <p>The code that I have tried is</p>
  
  <pre><code>static String REMOTE_LOCATION_WIN_PATTERN = "([a-zA-Z]:)?(\\\\[a-z  A-Z0-9_.-]+)+.(txt|gif|jpg|png|jpeg|pdf|doc|docx|xls|xlsx|DMS)\\\\?";
  
  static String REMOTE_LOCATION_LINUX_PATTERN = "^(/[^/]*)+.(txt|gif|jpg|png|jpeg|pdf|doc|docx|xls|xlsx|DMS)/?$";
  
  public boolean checkPathValidity(String filePath) {
  
     Pattern linux_pattern = Pattern.compile(REMOTE_LOCATION_LINUX_PATTERN);
     Pattern win_pattern = Pattern.compile(REMOTE_LOCATION_WIN_PATTERN);
     Matcher m1 = linux_pattern.matcher(filePath);
     Matcher m2 = win_pattern.matcher(filePath);
  
     if (m1.matches() || m2.matches()) {
        return true;
     } else {
        return false;
     }
  }
  </code></pre>
  
  <p>This function gives result true if path is valid in either windows/linux.
  The above function is not returning right result for some of the paths that contain dates, _ ? , * in their path.</p>