The idea is to replace the whole word (+)-glutamic: with "(+)-glutamic":. However escaping special characters as shown in the snippet doesn't seem to work.
If the special characters are not at the beginning of the string, then it works okay. I'm using \b to make sure only full words are matched, i.e. it should not match the substring in glutamic acid: {}.
Is there something I'm missing?
import re
pathways = "(+)-glutamic: {} glutamic acid: {}"
compound = "(+)-glutamic"
m = re.sub(r"\b{}:".format(re.escape(compound)), f'"{compound}":', pathways)
print(m)