Python Glossary Русский

all Python 3until 3.15Removed from the standard libraryterm

sre_compile / sre_constants / sre_parse

removed modules

Internal modules of the regular expression engine. Removed in Python 3.15 — use the public re module.

Syntax

import sre_parse  # до 3.15

These three modules — pattern parsing, compilation and the constants table — were internals of re but sat at the top level, and people got used to importing them directly. In 3.11 they moved inside the re package, leaving the old names as stubs with a warning, and 3.15 removed the stubs. To migrate, replace sre_compile.compile(p) with re.compile(p); sre_constants.error with re.error (re.PatternError since 3.13); flags such as sre_constants.SRE_FLAG_IGNORECASE with re.IGNORECASE. If you parsed patterns with sre_parse.parse, there is no public replacement: re._parser is private and carries no guarantees.

Examples

# Python 3.15+
try:
    import sre_parse
except ModuleNotFoundError as e:
    print(type(e).__name__)  # → ModuleNotFoundError
# Python 3.15+
import re
try:
    re.compile('(unclosed')
except re.error as e:
    print(type(e).__name__)  # → PatternError
print(bool(re.compile('abc', re.IGNORECASE).match('ABC')))  # → True
import re
import sre_constants
print(sre_constants.error is re.error)  # → True
print(sre_constants.SRE_FLAG_IGNORECASE == re.IGNORECASE)  # → True

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy