import re


def sanitize(name, space_allowed=False, replace_with_character="_"):
    """sanitizes string to remove unwanted characters

    Args:
        name ([type]): name to sanitize
        space_allowed (bool, optional): identify if space allowed in sanitized string.\
             Defaults to False.
        replace_with_character (str, optional): replacement character. Defaults to "_".

    Returns:
        string: sanitized string
    """
    if space_allowed:
        sanitized_name = re.sub(
            r"([^\sa-zA-Z0-9._-])", replace_with_character, name
        )
    else:
        sanitized_name = re.sub(
            r"([^a-zA-Z0-9._-])", replace_with_character, name
        )
    return sanitized_name