title: Java regex for Windows file path
body: <p>I'm trying to build a Java regex to search a .txt file for a Windows formatted file path, however, due to the file path containing literal backslashes, my regex is failing.</p>
  
  <p>The .txt file contains the line:</p>
  
  <pre><code>C\Windows\SysWOW64\ntdll.dll
  </code></pre>
  
  <p>However, some of the filenames in the text file are formatted like this:</p>
  
  <pre><code>C\Windows\SysWOW64\ntdll.dll (some developer stuff here...)
  </code></pre>
  
  <p>So I'm unable to use String.equals</p>
  
  <p>To match this line, I'm using the regex:</p>
  
  <pre><code>filename = "C\\Windows\\SysWOW64\\ntdll.dll"
  read = BufferedReader.readLine();
  
  if (Pattern.compile(Pattern.quote(filename), Pattern.CASE_INSENSITIVE).matcher(read).find()) {
  </code></pre>
  
  <p>I've tried escaping the literal backslashes, using the replace method, i.e:</p>
  
  <pre><code>filename.replace("\\", "\\\\");
  </code></pre>
  
  <p>However, this is failing to find, I'm guessing this is because I need to further escape the backslashes after the Pattern has been built, I'm thinking I might need to escape upto an additional four backslashes, i.e:</p>
  
  <pre><code>Pattern.replaceAll("\\\\", "\\\\\\\\");
  </code></pre>
  
  <p>However, each time I try, the pattern doesn't get matched.  I'm certain it's a problem with the backslashes, but I'm not sure where to do the replacement, or if there's a better way of building the pattern.  </p>
  
  <p>I think the problem is further being compounded as the replaceAll method also uses a regex, with means the pattern will have it's own backslashes in there, to deal with the case insensitivity.  </p>
  
  <p>Any input or advice would be appreciated.</p>
  
  <p>Thanks</p>