为什么在Python中re2模块的结果与re模块不同?

6

我尝试使用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不同(未找到=>返回None)?

re2版本为0.2.20。Python版本为2.7。

谢谢

1个回答

5

这是版本0.2.20的一个故障。参见此问题或此问题。你最好从github上克隆源代码然后安装,不要通过pip来安装。


哦,这个问题已经通过GitHub版本解决了。谢谢。 - Puffin GDI

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接