Skip to content Skip to sidebar Skip to footer

Replace Part Of A Url With Javascript

I've found lots of articles around matching the URL and then replacing a certain part of just that particular URL... BUT! The website I need to change has around 25,000 URLs with t

Solution 1:

You can use the replace:

url = url.replace('/p/', '/product/');

If you have string, then you can use regex:

myHtml.replace(/mysite\.com\/(p)\/.*/gi, 'product');

Solution 2:

You pinned javascript and jquery as tags: use replace with regex

exampe:

string.replace(/mysite\.com\/(.*?)\/(.*)/, 'mysite.com/product/\2');

please provide more informations, so we can help better

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