import re


def find_col_index(header, col_name):
    """ Extracts the column index of the given variable in the data.

    Given a list of headers, searches the list for one that first one that contains
    the col_name. Uses regex match to search through each header.

    Parameters
    ----------
    header : list of strs
        List of headers in the dataset.
    col_name : str
        Name of column to be indexed.

    Returns
    -------
    int
        If a match is found, returns the index. If no match, it raises an Exception.
    """
    pat = re.compile('^(")*%s(")*$' % col_name.lower())
    for i, _ in enumerate(header):
        if re.match(pat, header[i].lower()):
            return i
    raise Exception("Column name not found: %s" % col_name)