The function takes a string input and replaces certain words with others based on a pattern.
