'Replaces \'match\' through the correct replacement string.'

def replace(self, match):

    transformed = self._expression
    transformed = _DOLLAR.subn((lambda m: match.group(int(m.group(1)))), transformed)[0]
    def _one_char_case_change(match):
        'Replaces    one    character    case    changes.'
        if (match.group(1)[0] == 'u'):
            return match.group(1)[(-1)].upper()
        else:
            return match.group(1)[(-1)].lower()
    transformed = _ONE_CHAR_CASE_SWITCH.subn(_one_char_case_change, transformed)[0]
    def _multi_char_case_change(match):
        'Replaces    multi    character    case    changes.'
        if (match.group(1)[0] == 'U'):
            return match.group(1)[1:].upper()
        else:
            return match.group(1)[1:].lower()
    transformed = _LONG_CASEFOLDINGS.subn(_multi_char_case_change, transformed)[0]
    transformed = _replace_conditional(match, transformed)
    return unescape(fill_in_whitespace(transformed))
