def consume_until(line_iter, end_re):
    """
    Consume and return lines from the iterator until one matches 'end_re'.
    The line matching 'end_re' will not be returned, but will be consumed.
    """
    ret = []
    for l in line_iter:
        line = l.group(0)
        if end_re.search(line):
            break
        ret.append(line)
    return ret