Does Python optimize regexes?

Aahz aahz at
Sat Jul 3 16:36:40 CEST 2004

In article <mailman.296.1088566178.27577.python-list at>,
Jason Smith  <jhs at> wrote:
>The reason I asked is because I felt that re.compile() was less clear:
>someRegex = re.compile('searchforme')
>while something:
>	theString = getTheString()
>	if
>		celebrate()
>I wanted to remove someRegex since I can shave a line of code and some 
>confusion, but I was worried about in a loop.

My reasoning is slightly different.  I'm always forgetting with whether the pattern or string goes first; with re.compile, you
can't fail.  Yesterday I fixed a couple of bugs where someone else made
the same error....
Aahz (aahz at           <*>

"Typing is cheap.  Thinking is expensive."  --Roy Smith,

More information about the Python-list mailing list