I want to use javascript to extract a numeric part of a url. There is only ever supposed to be one set of numerals (aka – it will never be http://www.example.com/455/all/6). The set of numerals will not always be the same. How can I do this? I know that i can use this code
var urlPath = window.location.pathname;
to extract the url, but I don’t know how to go further.
urlPath.match(/\d+/)[0]will get the numbers. It doesn’t perform any sanity checks, though, and will fail if there are no numbers at all. For better results, try: