Deprecated replacement for emacs regex
Is there a (non-interactive) function in emacs lisp that replaces a matched regex on an arbitrary string?
i.e.
(sub regex search-string replace-string)
how in
(sub "[^.x/]" "beef./xxfoo" "")
;; => "./xx"
+3
djhaskin987
source
to share
1 answer
Yes, see function replace-regexp-in-string
. Just like this.
And to replace the corresponding text in the buffer you have replace-regexp
.
The replacement does not need to be a literal string, but can involve extracting portions of the match from regular expressions and other manipulations. Use C-h f
to see the document for these functions.
+2
Drew
source
to share