import re


def _clean_space(s: str):
    """Removes trailing and leading spaces and collapses multiple consecutive internal spaces to a single one.
    This is borrowed from sacrebleu:
    https://github.com/mjpost/sacreBLEU/blob/069b0c88fceb29f3e24c3c19ba25342a3e7f96cb/sacrebleu.py#L1077

    Parameters
    ----------
    s
        The input string

    Returns
    -------
    ret
        The cleaned string
    """
    return re.sub(r'\s+', ' ', s.strip())