Currently I have this for my regex replacement:
import re
line = re.sub(r"\bstr\b", ":class:`str`", line)
I want a result like below, where the <, >, and ` stop replacement from occurring, and no replacement occurs if inside square brackets. I tried implementing negative lookarounds for just one of the characters, but I couldn't make it work.
Example input:
line = r"""list of str and list of :class:`str` or :class:`string <str>` or Union[str, Tuple[int, str]]"""
Example output of what I am aiming for:
"list of :class:`str` and list of :class:`str` or :class:`string <str>` or Union[str, Tuple[int, str]]"