import re


def _remove_leading_trailing_nonalpha(string: str) -> str:
    """Remove leading or trailing non-alphanumeric characters."""
    return re.sub(r"[^0-9a-zA-Z]+$", "", re.sub(r"^[^0-9a-zA-Z]+", "", string))