What is the name of the Python module for regular expressions?

The story behind the answer

Python’s standard-library module for regular expressions is named re.

After import re, a program can search text, test patterns, extract matching substrings, split text, or perform replacements. Common module-level functions include re.search(), re.match(), re.findall(), and re.sub(). For repeated use, re.compile() creates a pattern object whose methods can be called efficiently and clearly.

The name re comes from “regular expression,” also commonly abbreviated RE. Regex and regexp are informal terms for the pattern language or for regular-expression tools, but they are not the name of Python’s built-in standard module. reg is not the standard-library module for this purpose. Python also has a third-party package called regex with additional features, which can cause confusion; installing it does not change the standard module’s name.

Regular-expression patterns use a compact notation: ^ and $ can mark string boundaries, character classes such as [A-Z] describe alternatives, and quantifiers such as * or + describe repetition. Raw strings, written with an r prefix, are often recommended for patterns because they reduce conflicts between Python string escaping and regular-expression escaping. The re module works with both Unicode strings and byte strings, but they must not be mixed in one operation.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: