如何更改网址路径的最后一个组件? [英] How can I change the last component of a url path?
本文介绍了如何更改网址路径的最后一个组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
"http://something.com:6688/remote/17/26/172"
如果我的值为172,我需要将网址更改为175
if I have the value 172 and I need to change the url to 175
"http://something.com:6688/remote/17/26/175"
我怎么能在JavaScript中这样做?
how can i do that in JavaScript?
推荐答案
var url = "http://something.com:6688/remote/17/26/172"
url = url.replace(/\/[^\/]*$/, '/175')
翻译:找一个斜杠 \ /
后跟任何数字 *
非斜杠字符 [^ \ /]
后跟字符串结尾 $
。
Translation: Find a slash \/
which is followed by any number *
of non slash characters [^\/]
which is followed by end of string $
.
这篇关于如何更改网址路径的最后一个组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文