I need a way to remove all whitespace from a string, except when that whitespace is between quotes.
result = re.sub(\'\".*?\"\', \"\", content)
You can use shlex.split for a quotation-aware split, and join the result using " ".join. E.g.
print " ".join(shlex.split('Hello "world this is" a test'))