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

[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 <address@hidden> 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


reply via email to

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