I have an array of phrases:
bannedWords = ['hi', 'hi you', 'hello', 'and you']
I want to take a sentence like "hi, how are tim and you doing" and get this:
", how are tim doing"
Exact case matching is OK - sorry, should have clarified.
I have an array of phrases:
bannedWords = ['hi', 'hi you', 'hello', 'and you']
I want to take a sentence like "hi, how are tim and you doing" and get this:
", how are tim doing"
Exact case matching is OK - sorry, should have clarified.
Since you want to remove extra spaces as well, the regex below should work better:
s = "Hi, How are Tim and you doing"
bannedWords = ['hi', 'hi you', 'hello', 'and you']
for i in bannedWords: s = re.sub(i + "\s*", '', s, flags = re.I)
print s
# ', How are Tim doing'