regex to remove lines made of only whitespace

Andreas Tawn andreas.tawn at ubisoft.com
Wed Aug 11 13:21:10 CEST 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