Normalize Whitespace

Replace multiple consecutive whitespace characters with a single space and trim edges.

Code

General
import re
return re.sub(r'\s+', ' ', s).strip()

Parameters

String with irregular whitespace

Server

More Python Snippets