col1 = "test xx" col2 = "xx" print "<%s>\n" % col1.replace(col2,"").strip()
import re col1 = "test xx" col2 = "xx" pattern = re.compile(" ?xx$") repl = "" result = re.sub(pattern,repl,col1) print "<%s> <%s> <%s>\n" % (col1,col2,result) <test xx> <xx> <test>