all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Help with regex including newline
@ 2012-03-28 22:03 Gregory Benjamin
  0 siblings, 0 replies; 3+ messages in thread
From: Gregory Benjamin @ 2012-03-28 22:03 UTC (permalink / raw
  To: help-gnu-emacs

I've been struggling with this for more than an hour...

I'm using GNU Emacs 24.0.93.2

Given the following text in a buffer:

<!-- this is some garbage that I want to match and
strip out of the buffer. It may span many lines before
reaching the end. -->

I wish to use M-x replace-regexp to delete the entire pattern,
including the opening '<' and closing '>'.

Using M-x re-builder, I came up with the following regexp:

<!--\(.\|^j\)*?-->

Note that the '^j' is actually entered by typing 'C-q C-j'.

This regular expression highlights the text correctly in re-builder,
but when I attempt to use it with M-x replace-regexp, it doesn't match
anything. I've tried a number of variations to no avail.

The intent of the regular expression is: "Match <!-- followed by
either any character that isn't a newline, or the newline character,
up to -->, but don't match past the > char." This last bit is
controlled by using non-greedy matching *? instead of the usual *.

Best,
Greg



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

* Re: Help with regex including newline
       [not found] <mailman.13.1332982418.20052.help-gnu-emacs@gnu.org>
@ 2012-03-29  7:05 ` José A. Romero L.
  0 siblings, 0 replies; 3+ messages in thread
From: José A. Romero L. @ 2012-03-29  7:05 UTC (permalink / raw
  To: gnu.emacs.help; +Cc: help-gnu-emacs

W dniu czwartek, 29 marca 2012, 00:03:13 UTC+2 użytkownik Gregory Benjamin napisał:
> I've been struggling with this for more than an hour...
> 
> I'm using GNU Emacs 24.0.93.2
> 
> Given the following text in a buffer:
> 
> <!-- this is some garbage that I want to match and
> strip out of the buffer. It may span many lines before
> reaching the end. -->
(...)

Hello Greg,

You may want to have a look here: http://www.emacswiki.org/emacs/MultilineRegexp

Cheers,
--
José A. Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)




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

* RE: Help with regex including newline
@ 2012-03-29 14:37 Buchs, Kevin
  0 siblings, 0 replies; 3+ messages in thread
From: Buchs, Kevin @ 2012-03-29 14:37 UTC (permalink / raw
  To: help-gnu-emacs, gregb

|     Using M-x re-builder, I came up with the following regexp:
|    <!--\(.\|^j\)*?-->
|    Note that the '^j' is actually entered by typing 'C-q C-j'.

Greg, the RE looks correct. I've not used re-builder, but I wonder how
you transfer the RE to the command prompt. If you yank it, will the ^j
be the same as C-q C-j entered at that prompt? I think that may need to
be entered interactively that way.

- Kevin






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

end of thread, other threads:[~2012-03-29 14:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-29 14:37 Help with regex including newline Buchs, Kevin
     [not found] <mailman.13.1332982418.20052.help-gnu-emacs@gnu.org>
2012-03-29  7:05 ` José A. Romero L.
  -- strict thread matches above, loose matches on Subject: below --
2012-03-28 22:03 Gregory Benjamin

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.