[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Newbie regexp question
From: |
Michael Slass |
Subject: |
Re: Newbie regexp question |
Date: |
Wed, 30 Oct 2002 17:24:21 GMT |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
Paul Cohen <paco@enea.se> writes:
>
>No that's not what I want. Let me rephrase in more general terms. I want to
>remove a number of character sequences for which the following holds:
>
>1) They run over multiple lines.
>2) They begin and end with well defined sequences of characters. (In my case
>with "<!--Test-->" and "<!--End of Test-->"). Let's call the delimiting
>character sequences for the start and and end token.
>3) They may contain any number of unknown (printable) characters between the
>start and end token.
>4) There may exist multiple instances of these character sequences in the
>file.
>
>/Paul
>
I think a lisp program would do better at this:
VERY LIGHTLY TESTED. MAKE BACKUPS BEFORE EXPERIMENTING WITH THIS!
(defun paulc-purge-html-test-sections (buffer)
"Delete all occurances of text between <!--Test--> and <!--End of Test-->,
inclusive."
(interactive "bPurge html test sections in buffer: ")
(save-excursion
(save-restriction
(goto-char (point-min))
(while (re-search-forward "<!--Test-->" nil t)
(let ((beg (match-beginning 0))
(end (progn (re-search-forward "<!--End of Test-->" nil t)
(match-end 0))))
(if end
(kill-region beg end)
(error "Unmatched \"<!--Test-->\" sequence at position %d"
beg)))))))
--
Mike Slass
Re: Newbie regexp question, Barry Margolin, 2002/10/30
Re: Newbie regexp question, Stefan Monnier <address@hidden>, 2002/10/30
Re: Newbie regexp question, kgold, 2002/10/31