unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* 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
* 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

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 --
     [not found] <mailman.13.1332982418.20052.help-gnu-emacs@gnu.org>
2012-03-29  7:05 ` Help with regex including newline José A. Romero L.
2012-03-29 14:37 Buchs, Kevin
  -- strict thread matches above, loose matches on Subject: below --
2012-03-28 22:03 Gregory Benjamin

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