title: Extract part of URL with Regex
body: <p>I have a URL that will always be in either this format</p>
  
  <p><code>http://domain.tld/foo/bar/boo</code></p>
  
  <p><code>http://www.domain.tld/foo/bar/boo</code></p>
  
  <p><code>http://sub.domain.tld/foo/bar/boo</code></p>
  
  <p><code>http://www.sub.domain.tld/foo/bar/boo</code></p>
  
  <p>I'd like to use Regex to extract <code>bar</code> from the url, regardless of the format.</p>
  
  <p>I am using JavaScript.</p>
  
  <p>I tried to break the url up using something like</p>
  
  <pre><code>var x = 'http://domain.tld/foo/bar/boo`'
  x.split(/^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/g)
  </code></pre>
  
  <p>but this doesn't really work nor does it help as I seem to get an array or items when I really just need the value at <code>bar</code></p>