title: Backslashes - Regular Expression - Javascript
body: <p>I wanted to build a JS function concatting a list of arguments to a valid path (since I could not be sure whether a part of the path is given with or without slashes)</p>
  
  <p>This is the function:</p>
  
  <pre><code>concatPath = function() {
      var path = "";
      for(var i = 0; i &lt; arguments.length; i++)   {
          path += arguments[i].replace("(\\|/)$|^(\\|/)", "") + "/";
      }
      return path;
  }
  </code></pre>
  
  <p>The used RegEx matched all beginning and ending slashes and backslashes on <a href="http://regexpal.com" rel="noreferrer">http://regexpal.com</a>
  But the function does not work properly (RegEx does not match).
  Furthermore, Chrome states</p>
  
  <p><strong>SyntaxError: Invalid regular expression: /()$|^()/: Unterminated group</strong></p>
  
  <p>when I just use the RegEx</p>
  
  <pre><code> (\\)$|^(\\)
  </code></pre>
  
  <p>However, using the RegEx </p>
  
  <pre><code> (\\)$|^(\\)
  </code></pre>
  
  <p>works fine.</p>
  
  <p>Is it too late or did I missed something special?</p>
  
  <p>Thanks in advance!</p>
  
  <p>Leo</p>