fork(9) download
  1. import re
  2.  
  3. prefixes = ['mr', 'smr']
  4. regex = r'\b(?:' + '|'.join(prefixes) + ')\.\s*'
  5. i = 'hi mr.john, smr. john, etc. Previous etc should not be removed'
  6. i = re.sub(regex,'',i)
  7. print(i)
  8.  
Success #stdin #stdout 0.03s 27704KB
stdin
Standard input is empty
stdout
hi john, john, etc. Previous etc should not be removed