Python Glossary Русский

all Python 3refunction

re.purge

cache

Clear the internal cache of compiled regular expressions.

Syntax

re.purge()

You almost never need this in application code: the cache is bounded and evicts old entries on its own. The honest use cases are benchmarking compilation speed or profiling memory, where a warm cache skews the numbers. Pattern objects you already hold keep working — purge drops the module's internal table, not your compiled patterns.

Examples

import re
print(re.purge())   # → None
pat = re.compile(r'\d+')
print(pat.findall('a1b22c'))   # → ['1', '22']
print(re.purge())   # → None
print(pat.findall('a1b22c'))   # → ['1', '22']

See also

Open in the full glossarydocs.python.orgReport an inaccuracy