re.findall() hangs in python

silverburgh.meryl at gmail.com silverburgh.meryl at gmail.com
Sun Apr 1 14:15:39 EDT 2007


On Apr 1, 5:23 am, irs... at gmail.com wrote:
> On Apr 1, 6:12 am, "silverburgh.me... at gmail.com"
>
> <silverburgh.me... at gmail.com> 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 [^"].

Thank you. Your suggestion solves my problem!




More information about the Python-list mailing list