【发布时间】:2013-12-10 18:42:35
【问题描述】:
有没有一种简单的方法可以将精确字符串匹配为re.compile 对象?例如,我想混合精确的字符串和正则表达式。
【问题讨论】:
标签: python regex python-3.x
有没有一种简单的方法可以将精确字符串匹配为re.compile 对象?例如,我想混合精确的字符串和正则表达式。
【问题讨论】:
标签: python regex python-3.x
您可能可以使用re.escape 转义字符串中的所有内容,然后将转义的字符串用作模式。
def transform(s):
return re.compile(re.escape(s))
【讨论】: