def line_filter_and_transform(filter_re, transform_re, repl, lines):
    """
    Transform and filter lines.

    Filter out lines that match filter_re.

    Transform remaining lines by transform_re and repl as a regular
    expression replace. If the regular expression is not matched, then
    the line is output as is.
    """
    output = []
    for line in lines:
        match = filter_re.match(line)
        if match:
            # Drop line matching filter_re
            continue
        output.append(transform_re.sub(repl, line))

    return output