import re


def normalize_whitespace(text):
    """
    Normalize whitespace. Strips the string of whitespace in both ends,
    and replaces all consecutive whitespace characters (including tabs,
    newlines and nonbreak space) with a single space.
    """
    return re.sub('(\s|\\xa0)+', ' ', text).strip()