By trent on 25 Oct in Programming
Basically the easiest solution I came up with is to use a regular expression to pull out all occurances of a /file.ext and then return the first occurance. So my solution looked like this:
var fn = path.match(/\/([a-z0-9_-]+\.\w+)/i);
return (fn == null)? “” : fn;
Pretty simple solution right? Where path is the full url, we perform a match to get all matches. If it found no matches we return “”. This means the file may not be within the url in the case that it is index.html or home.html, etc where it is the default. Hope this helps someone!