why re2 result different from re module in python?

  • Last Update :
  • Techknowledgy :

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)

Suggestion : 2

pyre2 is a Python extension that wraps Google’s RE2 regular expression library.,This version of pyre2 is similar to the one you’d find at facebook’s github repository except that the stated goal of this version is to be a drop-in replacement for the re module.,If you require the use of regular expressions over an arbitrary stream of bytes, then this library might not be for you.,Come up with regular expression problems using the regular python ‘re’ module.

The stated goal of this module is to be a drop-in replacement for re. My hope is that some will be able to go to the top of their module and put:

try:
import re2 as re
except ImportError:
   import re

However, there are times when you may want to be notified of a failover. For this reason, I’m adding the single function set_fallback_notification to the module. Thus, you can write:

try:
import re2 as re
except ImportError:
   import re
else:
   re.set_fallback_notification(re.FALLBACK_WARNING)
3._
>>> re.findall(r '.', '\x80\x81\x82')['\x80', '\x81', '\x82'] >>>
   re2.findall(r '.', '\x80\x81\x82')[]
>>> re.findall(r '.', '\x80\x81\x82')['\x80', '\x81', '\x82'] >>>
   re2.findall(r '.', '\x80\x81\x82')[]

After the prerequisites are installed, you can try installing using easy_install:

$ sudo easy_install re2

Alternative to those, you can clone this repository and try installing it from there. To do this, run:

$ git clone git: //github.com/axiak/pyre2.git
   $ cd pyre2.git
$ sudo python setup.py install

Suggestion : 3

A regular expression (shortened as regex or regexp;[1] sometimes referred to as rational expression[2][3]) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation. Regular expression techniques are developed in theoretical computer science and formal language theory. ,Because regexes can be difficult to both explain and understand without examples, interactive websites for testing regexes are a useful resource for learning regexes by experimentation. This section provides a basic description of some of the properties of regexes by way of illustration. ,Given regular expressions R and S, the following operations over them are defined to produce regular expressions: ,Also worth noting is that these regexes are all Perl-like syntax. Standard POSIX regular expressions are different.

( ? <= \.) {
   2,
}( ? = [A - Z])
$string1 = "Hello World\n";
if ($string1 = ~m / ..... / ) {
   print "$string1 has length >= 5.\n";
}
Hello World
has length >= 5.
$string1 = "Hello World\n";
if ($string1 = ~m / (H..).(o..) / ) {
   print "We matched '$1' and '$2'.\n";
}
We matched 'Hel'
and 'o W'.
$string1 = "Hello World\n";
if ($string1 = ~m / l + /) {
   print "There are one or more consecutive letter \"l\"'s in $string1.\n";
}