Which is faster...find or re. ?
joconnor at cybermesa.com
Fri Aug 2 19:48:16 CEST 2002
I'm doing some parsing on HTML files and lookfor for particular tags.
First off given a single line that I want to find a string in, would
it be quicker to do
if string.find(line, searchString) > -1:
result = re.compile (searchString).match(line)
Now, expanding the question, which would probably be quicker.
for line in file.readlines():
if string.find (....
fileContents = file.read()
searchResults = re.compile (searchString).search(fileContents).
and then looping over searchResults
More information about the Python-list