import re


def field_name_to_key(field_name):
    """Given a field_name from Formatter.parse(), extract the argument key.

    Args:
        field_name: expression used to identify the source of the value for
            a field. See string.Formatter.parse for more info.

    Returns:
        The name or index at the start of the field_name.
    """
    assert isinstance(field_name, str)
    assert len(field_name)
    m = re.match(r'^([^.[]+)', field_name)
    if not m:
        return None
    arg_name = m.group(1)
    if arg_name.isdigit():
        return int(arg_name)
    else:
        return arg_name