unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* silly regexp-replace question: how to delete empty lines
@ 2004-03-03  1:11 leo
  2004-03-03  6:25 ` Barry Margolin
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: leo @ 2004-03-03  1:11 UTC (permalink / raw)


hi there

in a buffer like

  text is here
  and here and
  here

  further text is here

  an the endtext

i want to delete the two empty lines by an regexp-replace.

so i started with _finding_ the lines. that's easy: "^$" is the regexp. but
obviouly (replace-regexp "^$" "ghdfg" nil nil nil) does nothing.;-)

SO in order to delete empty lines (i.e. to replace it with "") i have to
find the empty line _plus_ the linefeed.

so i tried (replace-regexp "^$
" "ghdfg" nil nil nil) where the linefeed was type as C-q C-j. but it
doesn't find anything.

any idea?

thanks, leo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: silly regexp-replace question: how to delete empty lines
  2004-03-03  1:11 silly regexp-replace question: how to delete empty lines leo
@ 2004-03-03  6:25 ` Barry Margolin
  2004-03-03  6:36 ` Sacha Chua
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Barry Margolin @ 2004-03-03  6:25 UTC (permalink / raw)


regexp-replace is the wrong command.  Use flush-lines.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: silly regexp-replace question: how to delete empty lines
  2004-03-03  1:11 silly regexp-replace question: how to delete empty lines leo
  2004-03-03  6:25 ` Barry Margolin
@ 2004-03-03  6:36 ` Sacha Chua
  2004-03-03 20:11 ` Peter Lee
  2004-03-03 23:16 ` Joe Fineman
  3 siblings, 0 replies; 9+ messages in thread
From: Sacha Chua @ 2004-03-03  6:36 UTC (permalink / raw)


"leo" <halloleo@noospaam.myrealbox.com> writes:

> i want to delete the two empty lines by an regexp-replace.

You can also use delete-matching-lines... =)

-- 
Sacha Chua <sacha@free.net.ph> - Ateneo CS faculty geekette
interests: emacs, gnu/linux, making computer science education fun
http://sacha.free.net.ph/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: silly regexp-replace question: how to delete empty lines
  2004-03-03  1:11 silly regexp-replace question: how to delete empty lines leo
  2004-03-03  6:25 ` Barry Margolin
  2004-03-03  6:36 ` Sacha Chua
@ 2004-03-03 20:11 ` Peter Lee
  2004-03-03 23:53   ` leo
  2004-03-03 23:16 ` Joe Fineman
  3 siblings, 1 reply; 9+ messages in thread
From: Peter Lee @ 2004-03-03 20:11 UTC (permalink / raw)


>>>> leo  writes:

    leo> so i tried (replace-regexp "^$ " "ghdfg" nil nil nil) where the
    leo> linefeed was type as C-q C-j. but it doesn't find anything.

The following works.

(replace-regexp "^
" "blank line
" nil nil nil)


---------------------
  text is here
  and here and
  here

  further text is here

  an the endtext

---------------------

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: silly regexp-replace question: how to delete empty lines
  2004-03-03  1:11 silly regexp-replace question: how to delete empty lines leo
                   ` (2 preceding siblings ...)
  2004-03-03 20:11 ` Peter Lee
@ 2004-03-03 23:16 ` Joe Fineman
  3 siblings, 0 replies; 9+ messages in thread
From: Joe Fineman @ 2004-03-03 23:16 UTC (permalink / raw)


M-x query-replace-regexp RET
C-q C-j C-q C-j + RET
C-q C-j RET

is what I would do.
-- 
---  Joe Fineman    jcf@TheWorld.com

||:  Ye shall know the truth, and the truth shall make you free,  :||
||:  but first it shall piss you off beyond belief.               :||

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: silly regexp-replace question: how to delete empty lines
  2004-03-03 20:11 ` Peter Lee
@ 2004-03-03 23:53   ` leo
  2004-03-04  1:31     ` Johan Bockgård
  0 siblings, 1 reply; 9+ messages in thread
From: leo @ 2004-03-03 23:53 UTC (permalink / raw)


thanks peter

now i recall: i guess, the fact that "^[C-j]" works but "^$[C-j]" doesn't,
is kind of a regexp bug/feature in emacs, isn't it?

cheers, leo

"Peter Lee" <pete_lee@swbell.net> wrote in message
news:uy8qhy9lp.fsf@swbell.net...
> >>>> leo  writes:
>
>     leo> so i tried (replace-regexp "^$ " "ghdfg" nil nil nil) where the
>     leo> linefeed was type as C-q C-j. but it doesn't find anything.
>
> The following works.
>
> (replace-regexp "^
> " "blank line
> " nil nil nil)
>
>
> ---------------------
>   text is here
>   and here and
>   here
>
>   further text is here
>
>   an the endtext
>
> ---------------------
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: silly regexp-replace question: how to delete empty lines
  2004-03-03 23:53   ` leo
@ 2004-03-04  1:31     ` Johan Bockgård
  2004-03-04 10:10       ` Alan Mackenzie
  0 siblings, 1 reply; 9+ messages in thread
From: Johan Bockgård @ 2004-03-04  1:31 UTC (permalink / raw)


"leo" <halloleo@noospaam.myrealbox.com> writes:

> now i recall: i guess, the fact that "^[C-j]" works but "^$[C-j]"
> doesn't, is kind of a regexp bug/feature in emacs, isn't it?

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

    For historical compatibility reasons, `^' can be used only at the
    beginning of the regular expression, or after `\(' or `\|'.

(info "(elisp)Regexp Special")

-- 
Johan Bockgård

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: silly regexp-replace question: how to delete empty lines
       [not found] <200403040341.i243ftF7381474@e1.ny.us.ibm.com>
@ 2004-03-04  4:07 ` Thomas L Roche
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas L Roche @ 2004-03-04  4:07 UTC (permalink / raw)


"leo" Wed, 3 Mar 2004 12:11:08 +1100
> in a buffer like

>   text is here
>   and here and
>   here

>   further text is here

>   an the endtext

> i want to delete the two empty lines by an regexp-replace.

Umm ... do you know that you don't need a regexp? You can just do

> M-x replace-string
> C-q C-j C-q C-j
> C-q C-j

That being said,

> M-x replace-regexp
> C-q C-j C-q C-j
> C-q C-j

also works ... but you're not really replacing regexp, just a fixed
string.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: silly regexp-replace question: how to delete empty lines
  2004-03-04  1:31     ` Johan Bockgård
@ 2004-03-04 10:10       ` Alan Mackenzie
  0 siblings, 0 replies; 9+ messages in thread
From: Alan Mackenzie @ 2004-03-04 10:10 UTC (permalink / raw)


Johan Bockgård <bojohan+news@dd.chalmers.se> wrote on Thu, 04 Mar 2004
02:31:27 +0100:
> "leo" <halloleo@noospaam.myrealbox.com> writes:

>> now i recall: i guess, the fact that "^[C-j]" works but "^$[C-j]"
>> doesn't, is kind of a regexp bug/feature in emacs, isn't it?

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

>     For historical compatibility reasons, `^' can be used only at the
>     beginning of the regular expression, or after `\(' or `\|'.

> (info "(elisp)Regexp Special")

Yes, it's a pain in the backside.  But leo could write his regexp thus:

"^\\($\\)[C-j]".

> -- 
> Johan Bockgård

-- 
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").

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-03-04 10:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-03  1:11 silly regexp-replace question: how to delete empty lines leo
2004-03-03  6:25 ` Barry Margolin
2004-03-03  6:36 ` Sacha Chua
2004-03-03 20:11 ` Peter Lee
2004-03-03 23:53   ` leo
2004-03-04  1:31     ` Johan Bockgård
2004-03-04 10:10       ` Alan Mackenzie
2004-03-03 23:16 ` Joe Fineman
     [not found] <200403040341.i243ftF7381474@e1.ny.us.ibm.com>
2004-03-04  4:07 ` Thomas L Roche

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).