Regular expressions in python
Sean 'Shaleh' Perry
shalehperry at attbi.com
Wed Jul 3 11:46:26 EDT 2002
On 03-Jul-2002 Graeme Longman wrote:
> Hi,
>
> I'm using the python module re to search through strings of html text
> but I have found that it is taking too long using the seach method.
>
> I am looping though a list of regular expressions and I find that it
> takes much longer when no match is found for the expression than it does
> when a match is found. Is this normal ?
>
> I have fixed the problem for now by using string.find() before searching
> the text but was wondering if anyone had any ideas on a better
> technique.
>
> Is there something else I should be using ? I am using '.*' and
> re.DOTALL in my expressions but that doesn't seem to be the problem.
>
> Thanks for any help in advance.
>
sometimes regexs are not the answer, sometimes they are the best answer.
string.find is sometimes a solution. Other times the htmllib module is a
better choice.
Perhaps if you pasted a sample we could help you decide.
More information about the Python-list
mailing list