fork download
  1. import re
  2. text = r"\( Na Cl_{2} \) and \( Fe k_{3} cl \)"
  3. print( re.sub(r'\\\(\s*([^()]*?)\s*\\\)', lambda x: f'\\( {"".join(c if c.isalnum() else "" for c in x.group(1))} \\)', text) )
Success #stdin #stdout 0.02s 9308KB
stdin
Standard input is empty
stdout
\( NaCl2 \) and \( Fek3cl \)