import re


def camel_to_snake(text):
    """
    Will convert CamelCaseStrings to snake_case_strings. Examples:

    >>> camel_to_snake('CamelCase')
    'camel_case'
    >>> camel_to_snake('CamelCamelCase')
    'camel_camel_case'
    >>> camel_to_snake('Camel2Camel2Case')
    'camel2_camel2_case'
    >>> camel_to_snake('getHTTPResponseCode')
    'get_http_response_code'
    >>> camel_to_snake('get2HTTPResponseCode')
    'get2_http_response_code'
    >>> camel_to_snake('HTTPResponseCode')
    'http_response_code'
    >>> camel_to_snake('HTTPResponseCodeXYZ')
    'http_response_code_xyz'
    >>> camel_to_snake('Double_Case')
    'double_case'
    >>> camel_to_snake('SW_Merch')
    'sw_merch'
    >>> camel_to_snake('Odd/Characters')
    'odd_characters'
    >>> camel_to_snake('With Spaces')
    'with_spaces'
    """
    # Load #
    result = text
    # Eliminate trailing spaces #
    result = result.strip(' ')
    # First step #
    try:
        result = re.sub('(.)([A-Z][a-z]+)',  r'\1_\2', result)
    except TypeError:
        print("The text received was '%s'" % result)
        raise
    # Second step #
    result = re.sub('([a-z0-9])([A-Z])', r'\1_\2', result)
    # Lower case the rest #
    result = result.lower()
    # Eliminate remaining spaces #
    result = result.replace(' ', '_')
    # Eliminate quote characters #
    result = result.replace('"', '')
    result = result.replace("'", '')
    # Eliminate parenthesis #
    result = result.replace("(", '')
    result = result.replace(")", '')
    # Eliminate special characters #
    result = result.replace('/', '_')
    # Eliminate double underscore #
    while '__' in result: result = result.replace('__', '_')
    # Return #
    return result