Regular Expression To remove spam links

My WordPress was recently hacked and now I’m trying to clean all the pharma links from years of XML database backups.

It seems RegEx is the way to do it but I’m no expert. I can’t quite get the expression to work. I’m trying to write an expression that searches for any link containing the word viagra or cialis, then replace the whole tag with nothing.

This is what I’ve got so far…

(<a href=".*(viagra|cialias).*>)(.*)(<.a>)

It works – but also picks up good links when they’re close by. For example, it will select all of this…

<a href="" style="text-decoration:none;color:#676c6c">gastritis</a>  check out <a href="">Junkan</a>, a short version of <a href="">Tokyo to Osaka</a> made especially for <a href="">Good</a>

I need it to stop after gastritis

I’m currently just using to run the expression, then I planned to copy and paste from ‘replace’ tab back into the XML file.

(And if you are a RegEx whizz, making the expression search for Viagra and Cialis in upper and lowercase would be awesome!)

Read more here: Regular Expression To remove spam links

Leave a Reply

Your email address will not be published. Required fields are marked *