Skip to content Skip to sidebar Skip to footer

Replace Part Of Url With Javascript

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: h

Solution 1:

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/"

Post a Comment for "Replace Part Of Url With Javascript"