The re module

The re module#

Python has robust support for regular expressions in the re module. There are several useful functions; we’ll focus first on findall. Here’s an example:

And here’s its docstring:

findall (pattern,string,flags=0)

Return a list of all non-overlapping matches in the string.

If one or more capturing groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group.

Empty matches are included in the result.

We’ll learn more about capturing groups soon.