【发布时间】:2013-05-20 23:21:20
【问题描述】:
我正在尝试删除 URL 的最后一个目录部分。我的网址如下所示:
https://my_ip_address:port/site.php?path=/path/to/my/folder.
点击按钮时,我想将其更改为
https://my_ip_address:port/site.php?path=/path/to/my。 (去掉最后一部分)。
我已经尝试过window.location.replace(/\/[A-Za-z0-9%]+$/, ""),结果是
https://my_ip_address:port/undefined.
我应该使用什么正则表达式来做到这一点?
【问题讨论】:
标签: javascript regex url path replace