Regular Expression Question

Paul Prescod paulp at ActiveState.com
Tue Apr 3 20:00:25 EDT 2001


Wesley Witt wrote:
> 
> This is probably a simple question, but I can't seem to find the answer
> anywhere.
> 
> I want a regular expression that will match ALL lines that do NOT contain
> the string "skip".  I have some backup logs that I need to filter the noise
> out of.

Why use a regular expression?

You can do something like this (untested):

for line in fileinput.readlines():
    if line.find("skip")==-1:
        print line

For me, regular expressions are a last resort because they are hard to
read later and often slower than string methods.

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list