title: Extract IDs from URLs
body: <p>The url of my website is in one of the following two formats:</p>
  
  <pre><code>Format 1: http://www.example.com/books/1309/angular-book 
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>Format 2: http://www.example.com/ShowBook.aspx?ID=1309
  </code></pre>
  
  <p>I can extract the entire URL using </p>
  
  <pre><code>var url = encodeURIComponent(window.location.href);
  </code></pre>
  
  <p>How can I extract the ID from the url (in this case "1309"), specifically when I do not know if the URL will appear as Format 1 or 2?</p>