I am trying to replace some text in a string. I have "Microsoft Inc." and I want to replace it as "Microsoft Incorporation". For this I have tried like
company = 'Microsoft Inc.'
key = 'Inc.'
pattern = r'\b' + key + r'\b'
# pattern = r'\b' + re.escape(key) + r'\b'
_change = 'Incorporation'
y = re.sub(pattern, _change, company)
print(y)
I dont see any replacements. but when I remove "." from company and key then it is working fine, but when there is "." in string it doesnt change any thing.