I'm writing some elisp code and would like to replace some string with some another string in a buffer. Which elisp function does that ? I did a search on documentation for the related function but all I'm getting is the interactive commands. Would love to see a sample code if possible.
1 Answer
Use functions re-search-forward
and replace-match
in a loop, or function perform-replace
. See the Elisp manual, node Search and Replace.
Sample code:
(while (re-search-forward "hello" nil t)
(replace-match "world"))