I need to extract the last subdirectory and the file name from an image like this (the subdirectory name is not consistent and the position of the ):
example.com/dw/image/v2/BFKH_PRD/on/demandware.static/-/Library-Sites-RefArchSharedLibrary/default/dw981dad25/Homepage/2021/11_NOV/1102/HPNAVTILES/1102_WGA_NAV_TILES_01_01.jpg?sw=40&q=100
I am using this js to pull out the file name, which works great, but I have no idea how to get the last subdirectory.
function() {
var url = {{INSERT URL}};
return url.substr(url.lastIndexOf('/')+1).split('?')[0];
}
Thanks a bunch!