Constructs a pattern to use with the method clean().

    The priority of the tags is echo_tags, then start_tags and finally end_tags.
    That means that in some cases a negative lookahead may be required, as the
    first match from left to right will be reported.

    See clean() for the meaning of each group.

    Args:
      echo_tags: list of re strings. These are tags that may output something.
      start_tags: list of re strings. Tags that typically do not output
        anything, like control structures.
      end_tags: list of re strings. All the closing tags.

    Returns:
      a RegexObject.

def get_pattern(echo_tags, start_tags, end_tags):
    """Constructs a pattern to use with the method clean().

    The priority of the tags is echo_tags, then start_tags and finally end_tags.
    That means that in some cases a negative lookahead may be required, as the
    first match from left to right will be reported.

    See clean() for the meaning of each group.

    Args:
      echo_tags: list of re strings. These are tags that may output something.
      start_tags: list of re strings. Tags that typically do not output
        anything, like control structures.
      end_tags: list of re strings. All the closing tags.

    Returns:
      a RegexObject.
    """
    return re.compile(
        '|'.join((
            LEADING_SPACES,
            NEW_LINE,
            r'(?P<echo>%s)' % '|'.join(echo_tags),
            r'(?P<start>%s)' % '|'.join(start_tags),
            r'(?P<end>%s)' % '|'.join(end_tags))),
        flags=re.MULTILINE)