I need to remove everything after the last '/'.
Source: /uploads/images/image1.jpg
Result: /uploads/images/
How do I do this with regular expression? I've tried different solutions, but it's not working. I get NULL as a result.
I need to remove everything after the last '/'.
Source: /uploads/images/image1.jpg
Result: /uploads/images/
How do I do this with regular expression? I've tried different solutions, but it's not working. I get NULL as a result.
No regex needed:
path = path.substring(0, path.lastIndexOf('/') + 1);
Reference: lastIndexOf()
, substring()
You might want to check beforehand, whether the string contains a slash:
var index = path.lastIndexOf('/');
if(index > -1) {
path = path.substring(0, index + 1);
}