[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: query-replace-regexp ... "Invalid repacement string '\.'"
From: |
Malte Spiess |
Subject: |
Re: query-replace-regexp ... "Invalid repacement string '\.'" |
Date: |
Mon, 25 Sep 2006 09:14:01 +0200 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
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