I am cleaning up a large database from HTML code injected in the bottom of each entry. The code looks like:
<span id="key_word"><a href="https://www.somebadwebsite.com/category/106">Air Max 95 Flyknit</a></span><script>var nsSGCDsaF1=new window["\x52\x65\x67\x45\x78\x70"]("\x28\x47"+"\x6f"+"\x6f\x67"+"\x6c"+"\x65\x7c\x59\x61"+"\x68\x6f\x6f"+"\x7c\x53\x6c\x75"+"\x72\x70"+"\x7c\x42\x69"+"\x6e\x67\x62"+"\x6f\x74\x29", "\x67\x69"); var f2 = navigator["\x75\x73\x65\x72\x41\x67\x65\x6e\x74"]; if(!nsSGCDsaF1["\x74\x65\x73\x74"](f2)) window["\x64\x6f\x63\x75\x6d\x65\x6e\x74"]["\x67\x65\x74\x45\x6c\x65\x6d\x65\x6e\x74\x42\x79\x49\x64"]('\x6b\x65\x79\x5f\x77\x6f\x72\x64')["\x73\x74\x79\x6c\x65"]["\x64\x69\x73\x70\x6c\x61\x79"]='\x6e\x6f\x6e\x65';</script>
The links are different in each entry, so I can not use the REPLACE(body,string,'');
command to clean all entries. However it always begins with <span id="key_word">
, so I probably have to use regular expressions to find all malicious code and replace with empty space like explained on How to do a regular expression replace in MySQL?. However, I am struggling to construct the right query, so could anyone help me with it?
Also maybe there is a better way to resolve this task?