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
If speed is not important, use regex:
import re somestring='this is some string rec' somestring = re.sub(' rec$', '', somestring)