[Tutor] Help with re in Python 3

Steven D'Aprano steve at pearwood.info
Sat Nov 5 02:03:34 CET 2011

Prasad, Ramit wrote:
>> m = re.search("[A-Z]{3}[a-z][A-Z]{3}", line)
> That is the expression I would suggest, except it is still more
> efficient to use a compiled regular expression like the original
> version.

Not necessarily. The Python regex module caches recently used regex 
strings, avoiding re-compiling them when possible.

However there is no guarantee on how many regexes are kept in the cache, 
so if you care, it is safer to keep your own compiled version.


More information about the Tutor mailing list