def filter_lines(lines, filter_regex, groups=None):
    """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.
    """
    pattern = re.compile(filter_regex)
    for line in lines:
        match = pattern.search(line)
        if match:
            if groups is None:
                yield line
            elif len(groups) == 1:
                yield match.group(groups[0])
            else:
                matched_groups = match.groupdict()
                yield tuple(matched_groups.get(group) for group in groups)
def filter_lines ( lines , filter_regex , groups = None ) : pattern = re . compile ( filter_regex ) for line in lines : match = pattern . search ( line ) if match : if groups is None : yield line elif len ( groups ) == 1 : yield match . group ( groups [ 0 ] ) else : matched_groups = match . groupdict ( ) yield tuple ( matched_groups . get ( group ) for group in groups )
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.