import re


def dtype_ripper(the_dtype, min_years, max_years):
    """Extract the range of years from the dtype of a structured array.

    Args:
        the_dtype (list): A list of tuples with each tuple containing two
            entries, a column heading string, and a string defining the
            data type for that column. Formatted as a numpy dtype list.
        min_years (list): The earliest years found in the imported data.
        max_years (list): The latest years found in the imported data.

    Returns:
        Updated lists of minimum and maximum years with the minimum
        and maximum found in data_array.
        The minimum and maximum years, as integers, that were contained
        in the column headings of the dtype definition.
    """

    # Strip the dtype into its constituent lists: column names and data formats
    colnames, dtypes = zip(*the_dtype)

    # Preallocate a list for the years extracted from the column names
    year_list = []

    # Loop over the list of column names, identify entries that have
    # the format specified by a regex, and add the matches to a list
    for name in colnames:
        year = re.search('^[1|2][0-9]{3}$', name)
        if year:
            year_list.append(year.group())

    # Identify the minimum and maximum years from the list of the years
    # in the column names and record them as integers instead of strings
    min_yr = int(min(year_list))
    max_yr = int(max(year_list))

    # Circumvents the action of .append() modifying in place the lists
    # passed to the function
    new_min_years = min_years + [min_yr]
    new_max_years = max_years + [max_yr]

    return new_min_years, new_max_years