The subject of regular expressions is quite deep, and it takes an immense amount of practice to get used to the special character syntax. Furthermore, the re module contains a vast set of methods available for performing searches using regular expressions. Upon completing the examples in this section, you should have a much deeper appreciation for how powerful regular expressions can be.
Under Python 3,
str objects use the full Unicode character set, and regular expression processing on a
str assumes that the pattern and input text are both Unicode. The escape codes described earlier are defined in terms of Unicode by default. Those assumptions mean that the pattern
\w+ will match both the words "French" and "Français". To restrict escape codes to the ASCII character set, as was the default in Python 2, use the
ASCII flag when compiling the pattern or when calling the module-level functions
The other escape sequences (
\S) are also processed differently for ASCII text. Instead of consulting the Unicode database to find the properties of each character,
re uses the ASCII definition of the character set.