re

The re module is used to perform regular-expression pattern matching and replacement in strings. Both ordinary and Unicode strings are supported. Regular-expression patterns are specified as strings containing a mix of text and special-character sequences. Because patterns often make extensive use of special characters and the backslash, they’re usually written as “raw” strings, such as r'(?P<int>\d+)\.(\d*)'. For the remainder of this section, all regular-expression patterns are denoted using the raw string syntax.

The following special-character sequences are recognized in regular expression patterns:

Character(s)Description
textMatches the literal string text.
.Matches any character except newline.
^Matches the start of a string.
$Matches the ...

Get Python: Essential Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.