title: Javascript regex to find a base URL
body: <p>I'm going mad with this regex in JS:</p>
  
  <pre><code>var patt1=/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*?(:[0-9]+)?(\/)?$/i;
  </code></pre>
  
  <p>If I give an input string like "http://www.eitb.com/servicios/concursos/516522/" this regex it's supossed to return NULL, because there are a "folder" after base URL. It works in PHP, but not in Javascript, like in this script:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var str="http://www.eitb.com/servicios/concursos/516522/"; 
  var patt1=/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*?(:[0-9]+)?(\/)?$/i;
  document.write(str.match(patt1));
  &lt;/script&gt;
  </code></pre>
  
  <p>It returns</p>
  
  <pre><code>http://www.eitb.com/servicios/concursos/516522/,,/516522,,/ 
  </code></pre>
  
  <p>The question is: why it is not working? How to make it work? </p>
  
  <p>The idea is to implement this regex in another function to get NULL when the URL passed is not in the correct format:</p>
  
  <p><a href="http://www.eitb.com/" rel="nofollow">http://www.eitb.com/</a> -> Correct
  <a href="http://www.eitb.com/something" rel="nofollow">http://www.eitb.com/something</a> -> Incorrect</p>
  
  <p>Thanks</p>