def sub(self, repl):
if self.asGroupList:<EOL><INDENT>warnings.warn("<STR_LIT>",<EOL>SyntaxWarning, stacklevel=<NUM_LIT:2>)<EOL>raise SyntaxError()<EOL><DEDENT>if self.asMatch and callable(repl):<EOL><INDENT>warnings.warn("<STR_LIT>",<EOL>SyntaxWarning, stacklevel=<NUM_LIT:2>)<EOL>raise SyntaxError()<EOL><DEDENT>if self.asMatch:<EOL><INDENT>def pa(tokens):<EOL><INDENT>return tokens[<NUM_LIT:0>].expand(repl)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>def pa(tokens):<EOL><INDENT>return self.re.sub(repl, tokens[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>return self.addParseAction(pa)<EOL>
Return Regex with an attached parse action to transform the parsed
result as if called using `re.sub(expr, repl, string) <https://docs.python.org/3/library/re.html#re.sub>`_.

Example::

    make_html = Regex(r"(\w+):(.*?):").sub(r"<\1>\2</\1>")
    print(make_html.transformString("h1:main title:"))
    # prints "<h1>main title</h1>"