def sanitize()

in submitit/core/utils.py [0:0]


def sanitize(s: str, only_alphanum: bool = True, in_quotes: bool = True) -> str:
    """Sanitize the string"""
    if only_alphanum:
        # Replace all consecutive non-alphanum character by _
        return re.sub(r"[\W_]+", "_", s)
    if in_quotes:
        # Escape double quotes in the original string and put it between double quotes
        s = s.replace('"', '\\"')
        s = f'"{s}"'
    return s