Use a regex that matches any of the words, ignoring case, and look up each replacement.
Solution
Python
importretext="I'm learning python at Sqatools"replacements={"python":"SQA","sqatools":"TOOLS"}pattern=r"\b("+"|".join(replacements)+r")\b"print(re.sub(pattern,lambdam:replacements[m.group(0).lower()],text,flags=re.IGNORECASE))
Output
I'm learning SQA at TOOLS
Line by line
Line 5
Builds the pattern \b(python|sqatools)\b.
Line 6
For every match the lambda returns the replacement, looked up in lower case.
Learn the concept
New to this topic? Read the lesson, then come back.