1. import re
    2. def titlecase(s):
    3. return re.sub(r"[A-Za-z]+('[A-Za-z]+)?",
    4. lambda mo: mo.group(0)[0].upper() +
    5. mo.group(0)[1:].lower(),
    6. s)
    7. text = "He's an engineer, isn't he?"
    8. print(titlecase(text))

    image.png