fork(1) download
  1. import re
  2.  
  3. text = """\
  4. Examination carried out in agreement with and in the presence of Dr John Doe (rhythmologist).
  5. Also, prof. N. SoAndSo was there.
  6. Professor Moriarty and Doctor Snuggles are fictional characters.
  7. False positive test: the Doctor. No match.
  8. """
  9.  
  10. print(
  11. re.sub(
  12. r'\b((?:[Pp]rofessor|[Dd]octor|[Pp]rof\.?|[DdPp]r\.?)\s+)([A-Z](?:\.|\w*)(?:\s+[A-Z]\w*)?)\b',
  13. r'\1[DOCTOR NAME]',
  14. text))
Success #stdin #stdout 0.01s 7112KB
stdin
Standard input is empty
stdout
Examination carried out in agreement with and in the presence of Dr [DOCTOR NAME] (rhythmologist).
Also, prof. [DOCTOR NAME] was there.
Professor [DOCTOR NAME] and Doctor [DOCTOR NAME] are fictional characters.
False positive test: the Doctor. No match.