문제

I try to use re2.

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

Result:

cde

But re2 result is different

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. How to hide the number 1?
  3. Why the result is different with re module (not found => return None)?

The re2 version is 0.2.20. and Python is 2.7

Thank you

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top