Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top