def reverse(regex, dict):
    replacer_regex = re.compile(
        """
        \\(\\?P\\<         
            (.+?)       
        \\>\\(.*?\\)\\)     
        """
        , re.VERBOSE)
return replacer_regex.sub(lambda m: dict[m.group(1)], regex)
How fill a regex string with parameters