Emacs Lisp has regexp-quote
to quote any string to match it literally. Apparently, there is no equivalent function to quote an arbitrary replacement string to use it literally. I mean, what could I use instead of the imaginary regexp-quote-replacement
in the following contrived[1] code?
(replace-regexp (regexp-quote "^$") (regexp-quote-replacement "\\&\\?"))
This code would be meant to replace a literal ^$
with a literal \&\?
.
--
[1] I know that I could use replace-string
in this case to achieve the same result.
replace-regexp
at all. – Drew Dec 02 '14 at 02:55regexp-quote
but which can be used for replacements.regexp-quote
cannot be used interactively. (2) The example provided was not an interactive call, it was a piece of elisp code. (3) Given (1) and (2), it seems safer to assume the objective is elisp code. I'll be happy to retract if the author says otherwise. – Malabarba Dec 02 '14 at 03:18regexp-quote
and learn about constructs such as\&
in theTO-STRING
, but apparently never noticed the several notes about the function not being intended for interactive use (the manual is even clearer about that than the doc string). – Drew Dec 02 '14 at 06:00