import re


def port_index(port):
    """
    Returns index in the port name like gfpga_pad_IO_A2F[1248]
    """
    indx_parser = re.compile(r"[a-zA-Z0-9_]*\[(?P<index>[0-9]+)\]$")
    match = indx_parser.fullmatch(port)
    index = -1
    if match is not None:
        index = int(match.group("index"))

    return index