Regex speed

Erik Heneryd erik at
Sat Oct 30 17:56:12 CEST 2004

Reinhold Birkenfeld wrote:
> OK, thank you. I now got rid of all the regexes, and - surprise,
> surprise - the speeds are almost equal. The bitter thing about it is
> that there are now twelve LOC more in Python that don't make
> understanding the code easier.

If your problem is that the re.compile() setup takes too long (compared 
to the time taken to do the actual matching/replacing), my guess is that 
you don't operate on that much data.  And if that's the case, does it 
really matter if it's a fraction of a second slower?

Note that str.find() currently uses the naive approach resulting in bad 
time complexity, so it's not suitable for larger data sets.  See


More information about the Python-list mailing list