import re


def snake_case(string, transform_grouped=True):
    """
    Transforms a string from camelCase to snake_case.

    Example:
        >>> snake_case('myHTTPMethod')
        'my_http_method'

    Pass transform_grouped as False to do not separate uppercase
    grouped letters.

    Example:
        >>> snake_case('myHTTPMEthod', transform_grouped=False)
        'my_httpmethod'
    """
    # Separate grouped uppercase letters eg. myHTTPMethod => myHTTP_Method
    if transform_grouped:
        string = re.sub(r'(?!^)([A-Z]+)([A-Z][0-9a-z])', r'\1_\2', string)

    return re.sub(r'(?!^)([0-9a-z])([A-Z])', r'\1_\2', string).lower()