7

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.

Sibi
  • 3,603
  • 2
  • 22
  • 35

1 Answers1

13

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"))
zck
  • 8,984
  • 2
  • 31
  • 65
Drew
  • 75,699
  • 9
  • 109
  • 225