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!
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/"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.