"""Utility functions.""" import re def remove_control_chars(s: str) -> str: r"""Remove all control characters except for allowed whitespace (\t, \n, \r).""" return re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]', '', s).strip()