fork download
  1. import re
  2.  
  3. abbreviations = ["Dr.", "Mrs.", "Mr.", "Ph.d"]
  4. rx = re.compile(r'''(?:{})|((?<=[a-z])\.(?=\s*[A-Z]))'''.format("|".join(abbreviations)))
  5.  
  6. data = "Man is weak.So they die. I have a Ph.d"
  7.  
  8. # substitute them first
  9. def repl(match):
  10. if match.group(1) is not None:
  11. return "#!#"
  12. return match.group(0)
  13.  
  14. data = rx.sub(repl, data)
  15. for sent in re.split(r"#!#\s*", data):
  16. print(sent.replace(".", ""))
  17.  
Success #stdin #stdout 0s 23296KB
stdin
Standard input is empty
stdout
Man is weak
So they die
I have a Phd