How to perform a query replace in emacs
To replace a character string everywhere that it occurs within the current buffer, there is two ways to do it
M-x replace-string
will ask you for the string you want to replace and what you want to replace it with. Once you provide these, it will make the change globally within the buffer.
M-%
will also prompt you for the string to search for and the string to replace it. It differs from m-x replace-string in that it asks for verification before making each change.
In order to enter control characters in either of the above, they will have to be preceded by C-q. For example, ^J is typed as C-q C-j.