def replace_word(word_input, one, two):
 regex = re.compile(('\\W(%s)(\\W|$)' % one), re.I)
 matches = regex.findall(word_input)
 if matches:
  for unused in matches:
   word_input = word_input.replace(one, two)
 return word_input

def replace_word ( word_input , one , two ) : regex = re . compile ( ( '\\W(%s)(\\W|$)' % one ) , re . I ) matches = regex . findall ( word_input ) if matches : for unused in matches : word_input = word_input . replace ( one , two ) return word_input
regex replace on just words .