首页 > 解决方案 > regex101.com 表达式在实际 python 中不起作用

问题描述

我需要一个正则表达式来在一串数字中找到确切数量的匹配数字。(例如,“正好三个重复数字”)

regex101 我得到了一个正常工作的正则表达式 (^|(.)(?!\2))(\d)\3{2}(?!\3)

但是当我在 python3.6 shell 中尝试它时,它失败了,match返回 None:

import re
three_char_re  = re.compile("(^|(.)(?!\2))(\d)\3{2}(?!\3)")
print(three_char_re.match("14551114"))

我的 python 环境和 regex101 之间是否有一些默认标志不同?我找不到正则表达式或测试输入的差异。

标签: pythonregex

解决方案



推荐阅读