From 7ed6c39bc6e60a6506181ac5ee252ba22b6ff03d Mon Sep 17 00:00:00 2001 From: Seth Dandridge Date: Wed, 24 Sep 2025 21:25:44 -0400 Subject: [PATCH] Docs: Clarify behavior of regular expression pattern caching as it relates to re.compile --- Doc/library/re.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 75ebbf11c8e47c..38b21f8c9717a8 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -915,10 +915,15 @@ Functions .. note:: - The compiled versions of the most recent patterns passed to - :func:`re.compile` and the module-level matching functions are cached, so - programs that use only a few regular expressions at a time needn't worry - about compiling regular expressions. + In addition to caching patterns passed to :func:`re.compile`, + the module maintains a small internal cache of regular + expressions passed to matching functions such as + :func:`re.search`, :func:`re.match`, and :func:`findall`, + even if the regular expressions were passed to + those functions as strings. Therefore, programs that use only + a few regular expressions at a time needn't worry about + compiling regular expressions. + .. function:: search(pattern, string, flags=0)