You can use this:
var result = window.location.pathname.replace(/\.[^\.\/]+$/, "").substr(1);
In javascript, you can access the various parts of the URL via the window.location object.
window.location.href - the entire URL
window.location.host - the hostname and port number - [www.sample.com]:80
window.location.hostname - the hostname - www.sample.com
window.location.pathname - just the path part - /search
window.location.search - the part of the URL after the ? symbol - ?q=demo
In your case, you can use window.location.pathname
and then if you need to strip the file extension off the filename, you can do that with some additional javascript:
var result = window.location.pathname.replace(/\.[^\.\/]+$/, "").substr(1);
This line of javascript will get the pathname component of the URL and then replace any file extension with ""
(effectively removing it) and the remove the leading slash.