* Using replace-regexp doesn't remove newlines?
@ 2005-07-15 12:32 ozark
2005-07-15 12:42 ` David Kastrup
0 siblings, 1 reply; 3+ messages in thread
From: ozark @ 2005-07-15 12:32 UTC (permalink / raw)
Some of the lines in the buffer have only the single character '#' in
them. I want to remove all such lines.
I tried doing the following:
M-x replace-regexp ^#$<RET><RET>
This replaces the lines with # in them by blank lines. As this is not I
want, I undid that, and instead tried
M-x replace-regexp ^#$C-qC-j<RET><RET>
This just says "Replaced 0 occurrences" and does nothing. Why is this
so? (I also tried C-m instead of C-j, it doesn't work either. I'm using
Linux)
I was able to achieve what I wanted by first replacing the # lines by
blank lines (the former of the two above), and then removing all blank
lines with
M-x replace-regexp C-qC-jC-qC-j<RET>C-qC-j<RET>
but in general, I may not want to remove all blank lines in the buffer.
So my question is:
a)Why doesn't M-x replace-regexp ^#$C-qC-j<RET><RET> work?
b)What is the regexp I must use to do what I intended?
Thanks,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Using replace-regexp doesn't remove newlines?
2005-07-15 12:32 Using replace-regexp doesn't remove newlines? ozark
@ 2005-07-15 12:42 ` David Kastrup
2005-07-15 12:47 ` ozark
0 siblings, 1 reply; 3+ messages in thread
From: David Kastrup @ 2005-07-15 12:42 UTC (permalink / raw)
"ozark" <shreevatsa@gmail.com> writes:
> Some of the lines in the buffer have only the single character '#' in
> them. I want to remove all such lines.
> I tried doing the following:
>
> M-x replace-regexp ^#$<RET><RET>
> This replaces the lines with # in them by blank lines. As this is not I
> want, I undid that, and instead tried
>
> M-x replace-regexp ^#$C-qC-j<RET><RET>
> This just says "Replaced 0 occurrences" and does nothing. Why is this
> so? (I also tried C-m instead of C-j, it doesn't work either. I'm using
> Linux)
Leave off the $. It is described in
(info "(emacs)Regexps")
`$'
is similar to `^' but matches only at the end of a line. Thus,
`x+$' matches a string of one `x' or more at the end of a line.
For historical compatibility reasons, `$' can be used with this
meaning only at the end of the regular expression, or before `\)'
or `\|'.
And the C-q C-j is quite enough to match the end of line.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Using replace-regexp doesn't remove newlines?
2005-07-15 12:42 ` David Kastrup
@ 2005-07-15 12:47 ` ozark
0 siblings, 0 replies; 3+ messages in thread
From: ozark @ 2005-07-15 12:47 UTC (permalink / raw)
Oh wow, thanks!
And thanks also for that emacs Regexps info page, I'd been looking for
it a long time, but just wasn't able to find it!
Thanks a lot,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-07-15 12:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-15 12:32 Using replace-regexp doesn't remove newlines? ozark
2005-07-15 12:42 ` David Kastrup
2005-07-15 12:47 ` ozark
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.