With reference to both of these links:
I am trying to use this method to be able to replace from a user inputted string using a dictionary created from a CSV but with case insensitivity.
The solution in question is as follows:
string=input("Please enter your string")
pattern = re.compile(r'(?<!\w)(' + '|'.join(re.escape(key) for key in sorted(dict.keys(),key=len, reverse=True)) + r')(?!\w)')
result = pattern.sub(lambda x: dict[x.group()], string)
print(result)
now I've tried using the RE.IGNORECASE
method on the end of my compile, as well as using the "Case Insensitive Dictionary Method" to change my initial dictionary but no matter each method I try I keep getting the same error whenever the input isn't an exact match for the keywords "Key Error 'keyword' doesn't match"
.