fork download
  1. import re
  2. text = r"{\' A}vila, Y{\`e}che, {'hallo}"
  3.  
  4. encodings = {
  5. "\\'": u'\u0300',
  6. "\\`": u'\u0302',
  7. }
  8.  
  9. def repl(m):
  10. encoding = m.group(1)
  11. string_content = m.group(2)
  12. if encoding in encodings:
  13. return string_content + encodings[encoding]
  14. return string_content
  15.  
  16. changed_text = re.sub(r'\{([^\w\s]+|_)\s*(\w)}', repl, text)
  17. print(changed_text)
Success #stdin #stdout 0.03s 9400KB
stdin
Standard input is empty
stdout
Àvila,  Yêche, {'hallo}