'Helper function for expanding a regular expression
in the replace field, if needed.'

def _replace_expand(self, m, repl):

    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
