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

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

[Fwd: end-of-line $ in multiline regexp replace]


From: Kevin Rodgers
Subject: [Fwd: end-of-line $ in multiline regexp replace]
Date: Fri, 31 Oct 2003 09:14:22 -0700
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Besides the documentation bug reported below by Alan, search.c:compile_pattern()
ought to report an error when $ is used incorrectly (and ^, \`, \', etc.).

--
Kevin Rodgers
--- Begin Message --- Subject: Re: end-of-line $ in multiline regexp replace Date: Fri, 31 Oct 2003 08:04:30 +0000 User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))
Leo <leo.broska@nospam.isys.com.au> wrote on Fri, 31 Oct 2003 11:22:25 +1100:
> hi there

> want to replace a multiline regexp by an one-line replacement. (in fact i
> just want to delete the line with the regexp.)

> so, at first i tried:
>         (query-replace-regexp ".*bytes.*$[ctrl-q][ctrl-j]" "" nil nil nil)
> which did not find any line. :-(

> then i just tried the same without the end-of-line "$":
>         (query-replace-regexp ".*bytes.*[ctrl-q][ctrl-j]" "" nil nil nil)
> and that worked.

> i don't understand, why? the first regexp ".*bytes.*$[ctrl-q][ctrl-j]" seems
> to me even >>more valid<< then the second one.

> any explanations?

Yes.  It's on the page "Regexp Special" in the Elisp manual:

:      For historical compatibility reasons, `$' can be used only at the
:      end of the regular expression, or before `\)' or `\|'.

I think this is crazy, but there you go.  There is no matching warning on
the corresponding page ("Regexps") in the Emacs manual (at least, there
wasn't in October 2001), which seems like a bug to me.

A workaround is to enclose such a `$' in parentheses:  "\($\)" [or
"\\($\\)" if you're writing it as a string in a Lisp program].

> tanks and cheers, leo

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").


--- End Message ---

reply via email to

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