def METHOD_NAME(self, m, repl):
    """ Helper function for expanding a regular expression
        in the replace field, if needed. """
    if self.engine.isre():
        try:
            new = m.expand(repl)
        except re.error:
            self.engine.report_error(repl, 'Invalid Replace Expression')
            new = None
    else:
        new = repl
    return new