Here you are:
import re
forbidden_patterns = ['Word1', 'Word2', 'Word3', '\d{4}']
string = "This is Word1 a list thatWord2 I'd like to 2016 be readableWord3"
for pattern in forbidden_patterns:
string = ''.join(re.split(pattern, string))
print(string)
Essentially, this code goes through each of the patterns in forbidden_patterns
, splits string
using that particular pattern as a delimiter (which removes the delimiter, in this case the pattern, from the string), and joins it back together into a string for the next pattern.
EDIT
To get rid of the extra spaces, put the following line as the first line in the for-loop:
string = ''.join(re.split(r'\b{} '.format(pattern), string))
This line checks to see if the pattern is a whole word, and if so, removes that word and one of the spaces. Make sure that this line goes above string = ''.join(re.split(pattern, string))
, which is "less specific" than this line.