String search vs regexp search

Anand Pillai pythonguy at Hotpop.com
Sun Oct 12 10:55:23 EDT 2003


To search a word in a group of words, say a paragraph or a web page,
would a string search or a regexp search be faster?

The string search would of course be,

if str.find(substr) != -1:
    domything()

And the regexp search assuming no case restriction would be,

strre=re.compile(substr, re.IGNORECASE)

m=strre.search(str)
if m:
   domything() 

I was about to do a test, then I thought someone here might have
some data on this already.

Thanks folks!

-Anan




More information about the Python-list mailing list