title: Javascript replace() regexp: nesting modifier
body: <p>I have a concatenated file path to a document on a server, e.g. </p>
  
  <pre><code>http://test:1234@192.168.0.12:5555/../test/directory/../name/sub/sub/../../file.js
  </code></pre>
  
  <p>and for some unknown reason the XHR request I send out to that "URL" returns error 404, while Chrome, when I give him the same path, makes</p>
  
  <pre><code>http://test:1234@192.168.0.12:5555/test/name/file.js
  </code></pre>
  
  <p>from it and returns the document okay. Now I am searching for a javascript regexp search/replace that can "clean" the path.</p>
  
  <p>This is what I have tried so far:</p>
  
  <pre><code>console.log(
      "http://test:1234@192.168.0.12:5555/../test/directory/../name/sub/sub/../../file.js"
      .replace(/([^\/])\/[^\/]*\/..\//g,'$1/')
  );
  </code></pre>
  
  <p>The regexp works except for nested matches: <code>/sub/dir/../../</code> is replaced to <code>/sub/../</code>, should be <code>/</code>.</p>
  
  <p>Is there a nesting modifier available?</p>