def transform_string()

in functions/data-processing-engines/bq-saved-query-executor/main.py [0:0]


def transform_string(text):
    """
    Transforms a string by removing non-alphanumeric characters (except spaces and hyphens)
    and replacing spaces with underscores, then trims any leading or trailing underscores or hyphens.

    Args:
        text (str): The input string to transform.

    Returns:
        str: The transformed string.
    """
    temp_text = re.sub(r"[^\w\s-]", " ", text)
    temp_text = re.sub(r"\s+", "_", temp_text)
    transformed_text = temp_text.strip("_-")
    return transformed_text