fork download
  1. import re
  2. s='U.S.A is abbr x.y is not. But I.I.T. is also valid ABBVR and so is M.Tech'
  3. print(re.sub(r'\b((?:[A-Z]\.)+)\.?|\.', lambda x: x.group(1).replace('.', '') if x.group(1) else ' ', s))
Success #stdin #stdout 0.03s 9344KB
stdin
Standard input is empty
stdout
USA is abbr  x y  is not  But IIT is also valid ABBVR and so is MTech