The url of my website is in one of the following two formats:
Format 1: http://www.example.com/books/1309/angular-book
OR
Format 2: http://www.example.com/ShowBook.aspx?ID=1309
I can extract the entire URL using
var url = encodeURIComponent(window.location.href);
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?