1>>> import re
2>>> def titlecase(s):
3... return re.sub(rb"[A-Za-z]+('[A-Za-z]+)?",
4... lambda mo: mo.group(0)[0:1].upper() +
5... mo.group(0)[1:].lower(),
6... s)
7...
8>>> titlecase(b"they're bill's friends.")
9b"They're Bill's Friends."
10