【问题标题】:Why re2 result different from re module in Python?为什么 re2 结果与 Python 中的 re 模块不同?
【发布时间】:2013-07-26 04:22:47
【问题描述】:

我尝试使用re2

import re
print re.search('cde', 'abcdefg').group(0)

结果:

cde

但是re2结果不同

import re2
print re2.search('cde', 'abcdefg').group(0)

结果:

1
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
  1. 为什么re2在每次执行新字符串模式时输出数字1
  2. 如何隐藏数字1
  3. 为什么结果与 re module 不同(未找到 => 返回无)?

re2 版本是 0.2.20。Python 是 2.7

谢谢

【问题讨论】:

    标签: python regex re2


    【解决方案1】:

    这是 0.2.20 版本的错误。请参阅此issue 或此one。您最好从 github 克隆源代码,然后安装它。不要通过 pip 安装。

    【讨论】:

    • 哦,这个问题已经被github版本解决了。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 2014-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    相关资源
    最近更新 更多