Greasemonkey:如何删除随机 url 部分?

Greasemonkey: How to remove random url parts?

我需要像这样更改图像...

https://www.website.com/images/stuff/95/jgfij/public/2019/09/cow.gif https://www.website.com/images/stuff/df3/4gy0/public/2015/03/horse.png https://www.website.com/images/stuff/odpk/f049/public/2020/08/dog.jpg

进入...

https://www.website.com/images/stuff/public/2019/09/cow.gif https://www.website.com/images/stuff/public/2015/03/horse.png https://www.website.com/images/stuff/public/2020/08/dog.jpg

我试过了,但没用

document.body.innerHTML = document.body.innerHTML.replace('https://www.website.com/images/stuff/*/public/,'https://www.website.com/images/stuff/public/');

我一直在努力寻找可以删除 url 特定部分之间所有内容的东西,但我从来没有找到任何运气。

更新:

您的示例可能不是您想要的。可能是以下内容:

blahblahblah.replace(new RegExp('https://www.website.com/images/stuff/.*/public/'),
    'https://www.website.com/images/stuff/public/');

您在正则表达式中缺少一个结束引号,并且有 /*,这意味着 "zero or more slashes",而您可能需要 .*、"zero or more of any character".

我还发现您必须将模式作为正则表达式而不是字符串传递。请参阅下面的评论。