RE strings (was: Variable Interpolation - status of PEP 215)
Quinn Dunkan
quinn at retch.ugcs.caltech.edu
Thu Jun 27 16:50:59 EDT 2002
On 21 Jun 2002 10:44:50 -0700, Cimarron Taylor <cimarron+google at taylors.org>
wrote:
> import re
> def parseline3(line):
> m = re.match(r'^EMP:([^,]*),([^,]*),([^,]*),([^,]*)$', line)
> if m:
> ...
>
>
>Unless I'm mistaken about how the re module works, parseline3 will
>recompile the regex each time it is called. parseline2 avoids this
You are. Mistaken, that is :)
Take a look at sre.py
Of course, if you did 20 regexes in the meanwhile, it would be recompiled.
I generally take the parseline2 approach anyway, though.
More information about the Python-list
mailing list