Why is the result of re2 different from the re-module in Python?

I am trying to use re2 .

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

Result:

 cde 

But the result of re2 is different from

 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' 
  • Why would re2 print the number 1 with every new line pattern?
  • How to hide the number 1 ?
  • Why is the result different from re module (not found => return None)?

The re2 version is 0.2.20. and Python 2.7

thanks

+6
source share
1 answer

This is a bug in version 0.2.20. See the issue or this one . It is better to clone the source from github and then install it. Do not install it through pip.

+5
source

Source: https://habr.com/ru/post/950319/


All Articles