I am able to replace a word in a string content using the following solution in a case insensitive method
http://code.activestate.com/recipes/552726/
import re
class str_cir(str):
''' A string with a built-in case-insensitive replacement method '''
def ireplace(self,old,new,count=0):
''' Behaves like S.replace(), but does so in a case-insensitive
fashion. '''
pattern = re.compile(re.escape(old),re.I)
return re.sub(pattern,new,self,count)
My problem is i need to replace exactly the word i provide like
para = "Train toy tram dog cat cow plane TOY Joy JoyTOY"
i need to replace the word "toy" with "ham" and i get
'Train HAM tram dog cat cow plane HAM Joy JoyHAM'
What i need is
'Train HAM tram dog cat cow plane HAM Joy JoyTOY'