re.findall() hangs in python

irstas at irstas at
Sun Apr 1 06:23:59 EDT 2007

On Apr 1, 6:12 am, " at"
< at> wrote:
> But when 'data' does not contain pattern, it just hangs at
> 're.findall'
> pattern = re.compile("(.*)<img (.*?) src=\"(.*?)img(.*?)\"(.*?)",
> re.S)

That pattern is just really slow to evaluate. What you want is
probably something more like this:

re.compile(r'<img [^>]*src\s*=\s*"([^"]*img[^"]*)"')

"dot" is usually not so great. Prefer "NOT end-character", like [^>]
or [^"].

More information about the Python-list mailing list