unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Joost Kremers <joostkremers@yahoo.com>
Subject: Re: Easy regexp issue
Date: 18 Jan 2007 19:32:17 GMT	[thread overview]
Message-ID: <slrneqvio7.nkf.joostkremers@j.kremers4.news.arnhem.chello.nl> (raw)
In-Reply-To: 1169145159.761299.289970@38g2000cwa.googlegroups.com

HS wrote:
> Hello everyone!
>
> 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")

try:

(replace-regexp-in-string "/" "\\\\" "c:/emacs/lisp")

in (the visual representation of) strings, a backslash is the escape
character, so when you want an actual backslash in a string, you must
escape it, i.e. write it as >>\\<<.

in regular expressions, the backslash is also an escape character, so that
if you want an actual backslash in a regexp, you have to escape it.

so, if you want to use an actual backslash in a regexp that is represented
as a string, you have to escape it with a backslash (for the regexp), and
then escape *both* of those backslashes with a backslash (for the string).

IOW, in your example, the regexp is "\\", which is a string representation
for >>\<<. so what you have is actually a single backslash regexp, which is
not a licit regexp.

-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)

  reply	other threads:[~2007-01-18 19:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-18 18:32 Easy regexp issue HS
2007-01-18 19:32 ` Joost Kremers [this message]
2007-01-19  7:28 ` Kevin Rodgers
     [not found] ` <mailman.3295.1169191738.2155.help-gnu-emacs@gnu.org>
2007-01-19  7:49   ` Barry Margolin
2007-01-19 13:29     ` HS
2007-01-22 19:26       ` Robert Thorpe
2007-01-20  6:09     ` Kevin Rodgers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=slrneqvio7.nkf.joostkremers@j.kremers4.news.arnhem.chello.nl \
    --to=joostkremers@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).