Use Regex to Remove Amazon Affiliate Tags from Wordpress Database?

illmasterj

BuSo Pro
Joined
Aug 5, 2018
Messages
462
Likes
402
Degree
2
Is there a simple way to clean up a very neglected WordPress site full of Amazon Associates links?

For example:

https://www.amazon.com/gp/product/1612334437/ref=as_li_tl?ie=UTF8&camp=1889&creative=390967&creativeASIN=1612434487&linkCode=as2&tag=eighty1-20&linkId=ZYR5Y578FDKDKN https://www.amazon.com/dp/B008V2OAV4?tag=forty4-20

Usually I use Notepad++ to replace everything after the last slash with nothing. But this doesn't work in the second use case.
 
Is there a simple way to clean up a very neglected WordPress site full of Amazon Associates links?

For example:

https://www.amazon.com/gp/product/1612334437/ref=as_li_tl?ie=UTF8&camp=1889&creative=390967&creativeASIN=1612434487&linkCode=as2&tag=eighty1-20&linkId=ZYR5Y578FDKDKN https://www.amazon.com/dp/B008V2OAV4?tag=forty4-20

Usually I use Notepad++ to replace everything after the last slash with nothing. But this doesn't work in the second use case.

For the first one use something like this: (REGEX)

Code:
Search: https://www.amazon.com/gp/product/([^\s]+)/([^\s]+)tag=([^\s]+)&([^\s]+)
Replace: https://www.amazon.com/gp/product/$1?tag=$3

Or replace with the tag that you want!

If you want to clean the seccond one (or change the tag) use this one:

Code:
https://www.amazon.com/dp/([^\s]+)?([^\s]+)tag=([^\s]+)
https://www.amazon.com/dp/$1/

(tested on Atom editor)
 
Thanks @DarkRed. I want to remove all tags from the site completely (will use your first and third methods) as I have a plugin that automatically appends the tag and adds a no follow to amazon.com links.

Is there a tool to run multiple regex replacements at once? I am doing more and more of these migrations, it will be nice to clean them up in bulk. Is Atom better than Notepad++?
 
Well in that case I would use this plugin: https://wordpress.org/plugins/better-search-replace/

With this code:

Code:
Search: amazon.com/gp/product/([^\s]+)/([^\s]+)">
Replace: amazon.com/gp/product/$1/">

Also check the variations like amazon.com/DP/ ...

Make sure to enable regular expression on "search flags":

YiG9Nba.png
 
Back