I am trying to remove comments from my TeX code. I want to trim text after %, but want to avoid the escaped \%.
I thought that this would do it
re.sub(r"([^%]*)([^\\][%])(.*)$", r"\1", "10 \% foo.% bar")
which outputs the almost right
'10 \\% foo'
expected output:
'10 \\% foo.'
Why does it trim away the last character before %? And, how can I avoid it?