import re


def clean(name):
    """Clean a :class:`str` into a valid variable name.

    Examples:
        >>> clean(' 32v2 g #Gmw845h$W b53wi ')
        'v2_g__Gmw845h_W_b53wi_'

    Args:
        name (str): A string to be cleaned.

    Returns:
        str: A string containing a valid variable name extracted from ``name``.

    Raises:
        ValueError: If name is only composed numbers or other invalid characters.

    """
    if re.match(r'^[^a-zA-Z_]+$\Z', name) is not None:
        raise ValueError('Invalid name: {} is only composed of invalid character and can not be cleaned.')

    # Remove uppercase
    name = name.lower()
    # Remove leading characters until we find a letter or underscore
    name = re.sub('^[^a-zA-Z_]+', '', name)
    # Remove invalid characters
    name = re.sub('[^0-9a-zA-Z_]', '_', name)

    return name