unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Malte Spiess <i1tnews@arcor.de>
Subject: Re: query-replace-regexp ... "Invalid repacement string '\.'"
Date: Mon, 25 Sep 2006 09:14:01 +0200	[thread overview]
Message-ID: <87hcyw2zba.fsf@trick.ulm.malte.spiess> (raw)
In-Reply-To: 85vencl9ar.fsf@lola.goethe.zz

David Kastrup <dak@gnu.org> writes:

> Malte Spiess <i1tnews@arcor.de> writes:
>
>> "s. keeling" <keeling@spots.ab.ca> writes:
>>
>>> Hi.  I was trying to make it easy on myself using q-r-r replacing
>>> '[^\]\.' (not a backslash, followed by a literal dot/period) with the
>>> string (sans quotes) '\.', essentially "escaping" every dot/period in
>>> the file.  "M-x query-replace" had no trouble with it but M-x
>>> query-replace-regexp refused, spouting the error message in the
>>> subject.
>>
>> In a regexp for a "\" you need to escape, so write "\\". "\]" is a
>> mistake.
>
> No, it isn't.  Inside of [], \ is not special.

Oh. Oops, sorry. Must admit I never used "\" inside of []. Didn't expect
a change there.

> Maybe something like
>
> M-x query-replace-regexp RET \(^\|[^\]\). RET \1\\. RET
>
> Or even
>
> M-x query-replace-regexp RET \(\(^\|[^\]\)\(\\\\\)*\). RET \1\\. RET
>
> (which considers a dot preceded by an even number of backslashes as
> unescaped).

In case he wants to replace the character before the "." as well (which
I doubt) '\\.' as a replacement string should do fine.

Else the proposed constructions with \(...\) and \1 (sometimes even \2
or \3) should work fine. This is a really useful feature, one should
learn how to use it to simplify lots of replacement tasks.

Greetings

Malte

  parent reply	other threads:[~2006-09-25  7:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-24 23:56 query-replace-regexp ... "Invalid repacement string '\.'" s. keeling
2006-09-25  6:33 ` Malte Spiess
2006-09-25  7:02   ` David Kastrup
     [not found]   ` <85vencl9ar.fsf@lola.goethe.zz>
2006-09-25  7:14     ` Malte Spiess [this message]
2006-09-25  6:55 ` David Kastrup
2006-09-25  7:17   ` Malte Spiess

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=87hcyw2zba.fsf@trick.ulm.malte.spiess \
    --to=i1tnews@arcor.de \
    /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).