import re


def find_links_by_regex(soup, regex):
    """ Find all the links in the HTML that match the given regular expression. """
    resultset = soup.findAll(text=re.compile(regex))
    links = []
    for r in resultset:
        parent = r.parent

        if parent.name == 'a':
            links.append(parent.attrs.get('href', ''))

    return links