import re


def extract_failed_tasks(text):
    """
    Given the HTML text for one day, get the failed tasks for that day
    :param text: HTML text for one day
    :return: List of failed task names
    """

    # Get all tasks in the section starting with "Failed Tasks" until we get up to "Succeeded" or "Pending"
    failed = re.findall("Failed Tasks:((.|\n)*?)(Succeeded|Pending)? Tasks:", text)
    # This is an array containing a tuple; take the first element and split it by newline to get individual build
    # failures
    jobs = failed[0][0].split("\n")
    # Job names are in the lines starting with "- "; extract them
    jobs = [re.findall("^-.*", x)[0] for x in jobs if len(re.findall("^-.*", x)) > 0]
    # Strip out extra characters
    jobs = [x.strip(": ").strip("- ") for x in jobs]
    return jobs