Python and regex special considerations
In this section, we will review differences with other flavors, how to deal with Unicode, and also differences in the re
module between Python 2.x and Python 3.
Differences between Python and other flavors
As we mentioned at the beginning of the book, the re
module has Perl-style regular expressions. However, that doesn't mean Python support every feature the Perl engine has.
There are too many differences to cover them in a short book like this, if you want to know them in-depth here you have two good places to start:
Unicode
When you're using Python 2.x and you want to match Unicode, the regex has to be Unicode escape. For example:
>>> re.findall(r"\u03a9", u"adeΩa") [] >>> re.findall(ur"\u03a9", u"adeΩa") [u'\u03a9']
Note that if you use Unicode characters but the type of the string you're using is not Unicode, python...