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="http://buy-viagra.net/" style="text-decoration:none;color:#676c6c">gastritis</a>  check out <a href="http://www.good.is/post/junkan-fixies-from-tokyo-to-osaka/">Junkan</a>, a short version of <a href="http://www.tokyo2osaka.com/">Tokyo to Osaka</a> made especially for <a href="http://www.good.is/">Good</a>

I need it to stop after gastritis

I’m currently just using http://regexr.com/ 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


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: