re Module Objects and Functions

The re module defines all regular expression functionality. Pattern matching is done directly through module functions, or patterns are compiled into regular expression objects that can be used for repeated pattern matching. Information about the match, including captured groups, is retrieved through match objects.

Python’s raw string syntax, r'' or r"", allows you to specify regular expression patterns without having to escape embedded backslashes. The raw-string pattern, r'\n', is equivalent to the regular string pattern, \\n. Python also provides triple-quoted raw strings for multiline regular expressions: r'''text''' and r"""text""".

Get Regular Expression Pocket Reference, 2nd 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.