I need to extract the full path to a file using regExp
mydomain.com/path/to/file/myfile.html
-> mydomain.com/path/to/file/
/mypath/file.txt
-> /mypath/
anyone?
Should be faster without RegExp:
path.substr(0, path.lastIndexOf('/') + 1);
Examples:
var path = "mydomain.com/path/to/file/myfile.html";
path.substr(0, path.lastIndexOf('/') + 1);
"mydomain.com/path/to/file/"
var path = "/mypath/file.txt";
path.substr(0, path.lastIndexOf('/') + 1);
"/mypath/"
var path = "file.txt";
path.substr(0, path.lastIndexOf('/') + 1);
""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With