regex to remove lines made of only whitespace

Steven D'Aprano steve at
Wed Aug 11 13:31:44 CEST 2010

On Wed, 11 Aug 2010 12:13:29 +0100, Chris Withers wrote:

> Hi All,
> I'm looking for a regex (or other solution, as long as it's quick!) that
> could be used to strip out lines made up entirely of whitespace.

def strip_blank_lines(lines):
    for line in lines:
        if not line.isspace():
            yield line

text = ''.join(strip_blank_lines(lines.split('\n')))


More information about the Python-list mailing list