Rename groups in regex pattern and enclose it in named group

def modify_pattern(self, pattern, group):
        """Rename groups in regex pattern and enclose it in named group"""
        pattern = group_regex.sub(r'?P<{}_\1>'.format(self.name), pattern)
        return r'(?P<{}>{})'.format(group, pattern)