Does Python optimize regexes?
aahz at pythoncraft.com
Sat Jul 3 16:36:40 CEST 2004
In article <mailman.296.1088566178.27577.python-list at python.org>,
Jason Smith <jhs at oes.co.th> wrote:
>The reason I asked is because I felt that re.compile() was less clear:
>someRegex = re.compile('searchforme')
> theString = getTheString()
> if someRegex.search(theString):
>I wanted to remove someRegex since I can shave a line of code and some
>confusion, but I was worried about re.search() in a loop.
My reasoning is slightly different. I'm always forgetting with
re.search 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 pythoncraft.com) <*> http://www.pythoncraft.com/
"Typing is cheap. Thinking is expensive." --Roy Smith, c.l.py
More information about the Python-list