<p>I need to write a regular expression that finds javascript files that match  </p>

<pre><code>&lt;anypath&gt;&lt;slash&gt;js&lt;slash&gt;&lt;anything&gt;.js
</code></pre>

<p>For example, it should work for both :</p>

<ul>
<li>c:\mysite\js\common.js (Windows)</li>
<li>/var/www/mysite/js/common.js (UNIX)</li>
</ul>

<p>The problem is that the file separator in Windows is not being properly escaped :</p>

<pre><code>pattern = Pattern.compile(
     "^(.+?)" + 
     File.separator +
     "js" +
     File.separator +
     "(.+?).js$" );
</code></pre>

<p>Throwing  </p>

<pre><code>java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence
</code></pre>

<p>Is there any way to use a common regular expression that works in both Windows and UNIX systems ?</p>

Does
```
Pattern.quote(File.separator)
```
do the trick?
EDIT: This is available as of Java 1.5 or later. For 1.4, you need to simply escape the file separator char:
```
```
"\\" + File.separator
```
```
Escaping punctuation characters will not break anything, but escaping letters or numbers unconditionally will either change them to their special meaning or lead to a
PatternSyntaxException
.
(Thanks
Alan M
for pointing this out in the comments!)