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

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

Re: Easy regexp issue


From: HS
Subject: Re: Easy regexp issue
Date: 19 Jan 2007 05:29:51 -0800
User-agent: G2/1.0

Thanks everyone! The problem was solved!
I wanted it for this:

(defun open-this-folder ()
  "Opens current buffer folder with explorer"
  (interactive)
  (open-folder default-directory))

(defun open-folder (folder)
  "Opens a folder with explorer (winxp only)"
  (interactive)
  (shell-command
   (concat "explorer " (replace-regexp-in-string "/" "\\\\\\\\"
folder)))
  (message (concat "Opening folder: " folder)))

Barry Margolin escreveu:

> In article <mailman.3295.1169191738.2155.help-gnu-emacs@gnu.org>,
>  Kevin Rodgers <kevin.d.rodgers@gmail.com> wrote:
>
> > HS wrote:
> > > I'm finding this quite odd:
> > > I want to replace all slashes for backslashes in a string, but i'm
> > > having trouble!
> > >
> > > Running this:
> > > (replace-regexp-in-string "/" "\\" "c:/emacs/lisp/")
> > > I get:
> > > Debugger entered--Lisp error: (error "Invalid use of `\\' in
> > > replacement text")
> > >
> > > And if I try:
> > > (replace-regexp-in-string "/" "\" "c:/emacs/lisp/")
> > > I get:
> > > Debugger entered--Lisp error: (scan-error "Unbalanced parentheses" 302
> > > 1)
> > >
> > > So, I don't see any other options!
> > > I know the problems is there because I replace for another string then
> > > it works:
> > > (replace-regexp-in-string "/" "x" "c:/emacs/lisp/")
> > > "c:xemacsxlispx"
> >
> > See the LITERAL argument in the doc string for replace-regexp-in-string:
> >
> > (replace-regexp-in-string "/" "\\" "c:/emacs/lisp/" nil t)
>
> Or
>
> (replace-regexp-in-string "/" "\\\\" "c:/emacs/lisp/")
>
> This is necessary because backslash is an escape character at two
> levels: Lisp strings and regexp replacement strings (e.g. the sequence
> \1 in the replacement represents a group matched in the regexp).  So the
> replacement string needs to be \\, and you need to escape each \ in the
> string.
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***



reply via email to

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