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
def remove_trailing_string(content, trailing): """ Strip trailing component `trailing` from `content` if it exists. """ if content.endswith(trailing) and content != trailing: return content[:-len(trailing)] return content