import re


def normalize(identifier):
    """Normalize a DOI."""

    identifier = identifier.lower()

    prefix = 'doi:'
    if identifier.startswith(prefix):
        identifier = identifier[len(prefix) :]
    else:
        pattern = re.compile(r'^(https?://)?(www\.)?(dx\.)?doi\.org/')
        if pattern.match(identifier) is not None:
            identifier = pattern.split(identifier)[-1]

    return identifier