regexp match string with word1 and not word2

MRAB google at mrabarnett.plus.com
Mon Apr 30 18:24:03 EDT 2007


On Apr 30, 6:49 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> In <1177946458.620210.68... at u30g2000hsc.googlegroups.com>, Flyzone wrote:
> > for y in range(0, len(skip_lst) ):
> >                  if (re.search(skip_lst[y], line)):
> >                               skip=1
> >                                break
>
> Please try to avoid unnecessary indexes::
>
>     for regexp in skip_list:
>         if re.search(regexp, line):
>             skip = True
>             break
>
> And if you don't intent to count the `skip`\s a `True` seems to be more
> readable.
>
Also try to avoid compiling the same regex repeatedly:

    compiled_skip_list = [re.compile(regexp) for regexp in skip_list]
    ...
    for regexp in compiled_skip_list:
        if regexp.search(line):
            skip = True
            break




More information about the Python-list mailing list