I have a bunch of strings, some of them have \' rec\'. I want to remove that only if those are the last 4 characters.
\' rec\'
So in other words I have
Starting in Python 3.9, you can use removesuffix:
Python 3.9
'this is some string rec'.removesuffix(' rec') # 'this is some string'