您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将Python 3.4的正则表达式“ fullmatch()”移植到Python 2

将Python 3.4的正则表达式“ fullmatch()”移植到Python 2

为了确保整个字符串匹配,您需要使用\Z 字符串结尾锚

def fullmatch(regex, string, flags=0):
    """Emulate python-3.4 re.fullmatch()."""
    return re.match("(?:" + regex + r")\Z", string, flags=flags)

\A锚是没有必要的,因为re.match()已经锚定匹配字符串的开始。

python 2022/1/1 18:36:58 有245人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶