Replace a word. GFG question

This is the ques.
https://practice.geeksforgeeks.org/problems/replace-a-word/0
I am solving this question with the help of KMP ALGO.
But KMP algo is not working when the txt has spaces in btween them now what to do