I need to replace a string containing a substring with another string. For example:
biography -> biography
biographical -> biography
biopic -> biography
bio-pic -> biography-pic
I watched a biographical movie -> I watched a biography movie
Here, all words on the left contain bio, so the whole word is replaced by biography. I am aware of string.replace() function, but it doesn't seem to work well here. I looked up regular expressions, but I'm not sure if re is the right library to solve the problem.
doesn't seem to work well here? What do you mean by that?biographytobiographygraphybio, and then callstring.replace(word, bio)for every such word'biology'which have nothing to do with'biography'but nevertheless contain'bio'?