Why do I have to pass a callable to re.sub to make an uppercase string?
问题 Below is a somewhat contrived example that get's at my eventual question... I would like to use regex to uppercase the first character of a possessive noun. Let's say that I have a regular expression that (probably poorly) matches possessive nouns. ie... ### Regex explanation ### # 1. match a word break # 2. match a word-like character and capture in a group # 3. lookahead for some more characters + the substring "'s" >>> my_re = re.compile(r"\b(\w)(?=\w+'s)") >>> re.search(my_re, "bruce's