用JavaScript替换URL的一部分
我发现了很多有关匹配URL,然后替换该特定URL的特定部分的文章...
I've found lots of articles around matching the URL and then replacing a certain part of just that particular URL...
但是!
我需要更改的网站大约有25,000个URL,下面的字符串我需要替换!我想做的是:
The website I need to change has around 25,000 URLs with the below string I need to replace! What I'm trying to do is:
mysite.com/p/product_name_10011029
mysite.com/p/product_name_10011029
然后替换:/p/
使用
mysite.com/product/product_name_10011029
mysite.com/product/product_name_10011029
同样,URL中有大约25,000个不同的页面带有/p/,因此它不能仅匹配一个URL
Again, there's 25,000 or so different pages that have /p/ in the URL so it can't match just one URL
您将javascript和jquery固定为标签: 使用正则表达式替换
You pinned javascript and jquery as tags: use replace with regex
示例:
string.replace(/mysite\.com\/(.*?)\/(.*)/, 'mysite.com/product/\2');
请提供更多信息,以便我们提供更好的帮助
please provide more informations, so we can help better