Why not use `re.replace(r"%.", replace_fn)`? Then it's only doing work for the stuff that needs translating.