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

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

Help with regex including newline


From: Gregory Benjamin
Subject: Help with regex including newline
Date: Wed, 28 Mar 2012 15:03:13 -0700
User-agent: Mutt/1.5.20 (2009-06-14)

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



reply via email to

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