def filter_lines(lines, filter_regex, groups=None):
pattern = re.compile(filter_regex)<EOL>for line in lines:<EOL><INDENT>match = pattern.search(line)<EOL>if match:<EOL><INDENT>if groups is None:<EOL><INDENT>yield line<EOL><DEDENT>elif len(groups) == <NUM_LIT:1>:<EOL><INDENT>yield match.group(groups[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>matched_groups = match.groupdict()<EOL>yield tuple(matched_groups.get(group) for group in groups)<EOL><DEDENT><DEDENT><DEDENT>
Filters out the lines not matching the pattern.

    Args:
      lines: list[string]: lines to filter.
      pattern: string: regular expression to filter out lines.

    Returns: list[string]: the list of filtered lines.