Regular expressions vs find?

David C. Ullrich ullrich at math.okstate.edu
Mon Jun 19 11:29:08 EDT 2000


Matthew Schinckel <matt at null.net> wrote in article
<20000619184000.639516 at 210.9.22.17>...
> "William Dandreta" <wjdandreta at worldnet.att.net> wrote:
> > I recently read a message that suggested that using regular
> > expressions might be faster than the find function. I've heard the
> > term regular expression used from time to time but I don't know what
> > it means. Could someone give me a simple explanation?
> > 
> > Bill
> 
> I have come across one example where re was much faster than using
> string.find: I was stripping out html tags, and doing a one line
> re.sub('<*?>','') was much faster than using string.find() and slice
> notation.

	??? You're not saying that the re was faster than find, you're saying
that it was faster than find _plus_ something else. Of course it is - if
regular expressions were not faster than equivalent blocks of code
they wouldn't be there.

	(For that matter the search itself would require some code, not
just one find - if you say find(s, '<*?>') you not going to find what
you're
looking for.)

> Try both, use the profiler, and compare. (I'll guess someone else will
> give an explanation about them).
> 
> Matt.
> 



More information about the Python-list mailing list