import re


def camel_to_snake(camel_str: str, delimiter: str = '_') -> str:
    """
    Converts camelCase to snake_case.

        https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case

    Args:
        camel_str (str): The camelCase string to convert to snake_case.
        delimiter (str): The delimiter to use for the snake_case. Defaults to '_'.

    Returns:
        str: Returns the snake_case representation of the passed camelCase string.

    Example:

        >>> 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('CamelCase', delimiter='.')
        'camel.case'

    """
    delimiter = str(delimiter)
    _str = re.sub('(.)([A-Z][a-z]+)', r'\1{}\2'.format(delimiter), str(camel_str))
    return re.sub('([a-z0-9])([A-Z])', r'\1{}\2'.format(delimiter), _str).lower()