reex.py 228 B

1234567891011
  1. import re
  2. def rename_groups(pattern, name_repl):
  3. def pattern_repl(match):
  4. return '(?P<{}>'.format(name_repl(match.group(1)))
  5. return re.sub(
  6. r'\(\?P<(.*?)>',
  7. pattern_repl,
  8. pattern,
  9. )