[英]Need help with javascript reg ex - how to remove part of a string
我需要删除最后一个'/'之后的所有内容。
来源: /uploads/images/image1.jpg
结果: /uploads/images/
我该如何使用正则表达式呢? 我尝试了不同的解决方案,但是没有用。 结果是NULL。
无需正则表达式:
path = path.substring(0, path.lastIndexOf('/') + 1);
参考: lastIndexOf()
, substring()
您可能需要事先检查字符串是否包含斜杠:
var index = path.lastIndexOf('/');
if(index > -1) {
path = path.substring(0, index + 1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.