I need to replace German Umlauts (Ä, ä, Ö, ö, Ü, ü, ß) with their two-letter equivalents (Ae, ae, Oe, oe, Ue, ue, ss).
Currently, I have this function, but the string's length changes:
def _translate_umlauts(s):
"""Translate a string into ASCII.
This Umlaut translation comes from http://stackoverflow.com/a/2400577/152439
"""
trans = {"\xe4" : "ae"} # and more ...
patt = re.compile("|".join(trans.keys()))
return patt.sub(lambda x: trans[x.group()], s)
However, I have the requirement that the string's total length should not change. For example, Mär should become Mae.
Any help in deriving the appropriate solution (regex?) is greatly appreciated :)