help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: double backslash problem in elisp


From: Teemu Likonen
Subject: Re: double backslash problem in elisp
Date: Fri, 21 Aug 2009 13:11:53 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

On 2009-08-21 02:43 (-0700), Xah Lee wrote:

> this is really a strang error.
>
> eval this:
> (replace-regexp-in-string "/" "\\" "//169.254.153.147/xah/Documents/
> alice artwork scans/")
>
>
> i get this error:
>
> Debugger entered--Lisp error: (error "Invalid use of `\\' in
> replacement text")

> any idea why?

Because backslash already has back-reference meaning in replace strings
(\&, \1, \2 ...). Hence a single backslash is illegal. So, you want a
single backslash literally in the replace string. First you put double
backslash to escape the special meaning in Lisp strings ("\\"), then you
must double it to escape the special meaning in regexp replace strings
("\\\\").

Alternatively you can give non-nil LITERAL argument for
replace-regexp-in-string; this takes out the special regexp meaning. So
these are the options:

    (replace-regexp-in-string "/" "\\\\" "string")
    (replace-regexp-in-string "/" "\\" "string" nil t)

> basically am trying to prepare a path to feed to w32-shell-execute.

Note that you may need shell-quote-argument too.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]