组合多个正则表达式替代

时间:2014-07-22 17:24:54

标签: python regex

我在python中使用re库:

现在我有多个替换,例如:

sentence = re.sub(" between | for | from ", " preposition ", sentence)
sentence = re.sub(" cake | cookies ", " food ", sentence)

......等等

示例输入:

I like cookies from safeway

输出:

I like food preposition safeway

有没有办法可以更有效地结合这些?

0 个答案:

没有答案