I'd like to remove the filename from a path using JavaScript
var urlstr = '/this/is/a/folder/aFile.txt';
var r = /[^\/]*$/;
urlstr.replace(r, ''); // '/this/is/a/folder/'
You haven't specified any sample inputs.
Assuming you always have a directory then the following will work. It takes everything up to (but not including) the last slash.
test = "/var/log/apache2/log.txt";
console.log(test.substring(0, test.lastIndexOf("/")));
You can use substring and indexOf:
var url = 'asdf/whatever/jpg.image';
url.substring(0, url.lastIndexOf('/'))