用 JavaScript 替换部分 URL [英] Replace part of URL with JavaScript

查看:34
本文介绍了用 JavaScript 替换部分 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 JavaScript 替换部分 URL,但愚蠢的正则表达式让我头疼.我想从这个切换:

I want to replace part of the URL with JavaScript but stupid regex is giving me headaches. I want to switch from this:

http://website.com/test.html/post/something-else/

为此:

http://website.com/post/something-else/

有什么想法吗?谢谢!

推荐答案

使用 replace() 函数

Use replace() function

var url = 'http://website.com/test.html/post/something-else/'
url = url.replace('/test.html','')
console.log(url) // "http://website.com/post/something-else/"

这篇关于用 JavaScript 替换部分 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆