title: How to extract base URL from a string in JavaScript?
body: <p>I'm trying to find a relatively easy and reliable method to extract the base URL from a string variable using JavaScript (or jQuery).</p>
  
  <p>For example, given something like:</p>
  
  <pre>http://www.sitename.com/article/2009/09/14/this-is-an-article/</pre>
  
  <p>I'd like to get:</p>
  
  <pre>http://www.sitename.com/</pre>
  
  <p>Is a regular expression the best bet? If so, what statement could I use to assign the base URL extracted from a given string to a new variable?</p>
  
  <p>I've done some searching on this, but everything I find in the JavaScript world seems to revolve around gathering this information from the actual document URL using <em>location.host</em> or similar.</p>