Documentation
The current documentation for the re.compile function mentions that compiled regular expressions are cached, but the wording could be more precise to clarify that this caching also applies to patterns passed as strings to other module functions (e.g., re.search, re.match). This change would help guide developers away from unnecessarily calling re.compile.
This abbreviated code snippet demonstrates the behavior I am referring to:
import re
re.match(r"fo+", "fooooooo")
for cache_entry in re._cache.items():
print(cache_entry)
#> ((<class 'str'>, 'fo+', 0), re.compile('fo+'))
Linked PRs
Documentation
The current documentation for the
re.compilefunction mentions that compiled regular expressions are cached, but the wording could be more precise to clarify that this caching also applies to patterns passed as strings to other module functions (e.g.,re.search,re.match). This change would help guide developers away from unnecessarily callingre.compile.This abbreviated code snippet demonstrates the behavior I am referring to:
Linked PRs