re.match
returns None
if it cannot find a match. Probably the cleanest solution to this problem is to just do this:
# There is no need for the try/except anymore
match = re.match(r'^(\S+) (.*?) (\S+)$', full)
if match is not None:
clean = filter(None, match.groups())
else:
clean = ""
Note that you could also do if match:
, but I personally like to do if match is not None:
because it is clearer. "Explicit is better than implicit" remember. ;)