While waiting for the real thing my workaround is to use this:
def re_sub(pattern, repl, text):
groups = re.match(pattern, text)
if groups:
for i in range(1, groups.lastindex + 1):
repl = repl.replace('\\{}'.format(i), groups[i])
return repl
It works just fine with simple cases like:
>>> re_sub('(\d{3}).*(\d{3}).*(\d{4})', r'(\1) \2-\3', '1234567890')
'(123) 456-7890'
>>> re_sub('(\d{3}).*(\d{3}).*(\d{4})', r'(\1) \2-\3', '123 456 7890')
'(123) 456-7890'