[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how can I make regexp expression effective across many lines
From: |
Pascal Bourguignon |
Subject: |
Re: how can I make regexp expression effective across many lines |
Date: |
Mon, 29 Jan 2007 22:26:53 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux) |
"Michael Chen" <vancouver.michael@gmail.com> writes:
> Hi, there, I have problem with newlines in regexp. Here is what I want
> to do: delete anything between <FORM> to TIP OF THE WEEK inclusively.
> There are many lines in between. Any regex I tried can not go through
> the newline. Any idea? Thanks.
Well, . matches anything but a newline. So you could build a regexp
matching anything including a newline as: "\\(.\\|\n\\)*"
Now, you want it shy, to find the first occurence of "TIP OF THE
WEEK", so use *? instead of *
"<FORM>\\(.\\|\n\\)*?TIP OF THE WEEK"
But in lisp code, it's easier to just search the start tag and then
search the end tag:
(delete-region
(if (search-forward "<FORM>")
(match-beginning 0)
(error "No <FORM>"))
(if (search-forward "TIP OF THE WEEK")
(match-end 0)
(error "No TIP OF THE WEEK")))
no need for a regexp here...
--
__Pascal Bourguignon__ http://www.informatimago.com/
PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.