regex to remove lines made of only whitespace

Andreas Tawn andreas.tawn at ubisoft.com
Wed Aug 11 07:21:10 EDT 2010


> 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.
> 
> eg:
> 
> 'x\n \t \n\ny' -> 'x\ny'
> 
> Does anyone have one handy?
> 
> cheers,
> 
> Chris

for line in lines:
    if not line.strip():
        continue
    doStuff(line)

cheers,

Drea



More information about the Python-list mailing list