python - 用于从字符串中清除禁用单词列表的正则表达式
问题描述
我正在关注此链接中接受的答案: Replace all words from word list with another string in python
尽管完全按照上述解决方案中的描述执行代码,但我似乎无法从字符串中删除字符。我在控制台中没有收到任何错误。谁能指出我做错了什么?这是一个可重现的例子。谢谢你。
example = "(-) This is an example of a string € which is + not being cleaned // correctly"
prohibited_strings = ["(-)","€","+","//"]
regex_cleaner = re.compile(r'\b%s\b' % r'\b|\b'.join(map(re.escape, prohibited_strings)))
example = regex_cleaner.sub("", example)