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

[英]Why re2 result different from re module in Python?


I try to use re2.

我尝试使用re2。

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

Result:

结果:

cde

But re2 result is different

但是re2的结果是不同的

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

Result:

结果:

1
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
  1. Why re2 output number 1 when every execution new string pattern?
  2. 为什么每次执行新的字符串模式时re2输出数字1?
  3. How to hide the number 1?
  4. 如何隐藏数字1?
  5. Why the result is different with re module (not found => return None)?
  6. 为什么结果与re模块不同(找不到=>返回None)?

The re2 version is 0.2.20. and Python is 2.7

re2版本是0.2.20。和Python是2.7

Thank you

谢谢

1 个解决方案

#1


5  

This is a bug of version 0.2.20. See this issue or this one. You'd better clone the source from github and then install it. Don't install it via pip.

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


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/07/26/d42064f689b07a14a6e9de05281d66fb.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号