string= "'Patriots', 'corona2020','COVID-19','coronavirus','2020TRUmp','Support2020Trump','whitehouse','Trump2020','QAnon','QAnon2020',TrumpQanon"
badwords = ['qanon', 'trump', 'corona', 'COVID']
If a compound in the string contains the sub-string of badwords, then that compound must be deleted from the string. For instance, we have COVID in the badwords, then COVID-19 should be removed in the string.
I tried to use re module like this, but failed:
import re
badwords = ['qanon', 'trump', 'corona', 'COVID']
string = "'Patriots', 'corona2020','COVID-19','coronavirus','2020TRUmp','Support2020Trump',Trump2020,'QAnon'"
for each in badwords:
print(re.findall ('[0-9a-zA-Z]+'+each,string,flags=re.IGNORECASE)+\
re.findall (each+'[0-9a-zA-Z]+',string,flags=re.IGNORECASE))
what I want: a new string "'Patriots','whitehouse'" should return.