import re


def _parse_single_term(ele, string, line, type_in, group=1):
    """ Stereotyped approach to quickly test for matches to a particular string.

    Keyword arguments:

    ele -- Currently saved element

    string -- The string to search for. Expects at least one group.

    line -- Current line being searched.

    type_in -- python type to coerce found results to.

    group -- the group number. Defaults to 1, but can be overridden.

    Returns:
    The extracted element of type determined by type_in, or np.nan
    """
    if ele is None:
        ele_s = re.search(string, line)
        if ele_s:
            return type_in(ele_s.group(group))
    else:
        return ele