import re


def _parse_key(key):
    """Parse the input key into an int, antpol tuple, or string.

    Parameters
    ----------
    key : str
        Input string to parse.

    Returns
    -------
    out_key : int or tuple or str
        Parsed key as an int, antpol tuple, or string.

    """
    try:
        # is key an int?
        return int(str(key))
    except ValueError:
        # is key an antpol tuple?
        antpol_regex = r"(\([0-9]*?, \'[xyne]\'\))"
        matches = re.findall(antpol_regex, key)
        try:
            # split tuple into antenna number and polarization
            ant, pol = matches[0][1:-1].split(",")
            # extract just polarization character
            pol = pol[-2]
            return tuple((int(ant), str(pol)))
        except IndexError:
            # treat it as a string
            return str(key)