Replace part of URL with JavaScript

2019-07-10 18:50发布

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/

to this:

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

Any ideas? Thanks!

1条回答
2楼-- · 2019-07-10 19:23

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/"
查看更多
登录 后发表回答