import re


def parse_td_links(ctx, raw_links, doc_id):
    """
    Parsing links contained in the last <td> elements.
    returns: list of tuples
    i.e. [(url, type), (url, type)]
    """
    links = []
    # https://regex101.com/r/7iAqds/1
    links_n_types_patt = re.compile(r"href='(.*?)'.*?title='(.*?)'")
    for url_n_type in links_n_types_patt.findall(raw_links):
        link = url_n_type[0]
        l_type = None  # link type
        if 'PDF' in url_n_type[1].upper():
            l_type = 'PDF'
        elif 'ZIP' in url_n_type[1].upper():
            l_type = 'ZIP'
        elif 'HTML' in url_n_type[1].upper():
            l_type = 'HTML'
        else:
            continue

        links.append((link, l_type))
    return links