From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Michael Slass Newsgroups: gmane.emacs.help Subject: Re: Newbie regexp question Date: Wed, 30 Oct 2002 21:37:01 GMT Organization: AT&T Broadband Sender: help-gnu-emacs-admin@gnu.org Message-ID: References: <3DBFF5F8.B78A64CA@enea.se> <8765vkkkko.fsf@fbigm.here> <3DC00D40.B76302FD@enea.se> <873cqnq0vn.fsf@fbigm.here> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1036014134 23670 80.91.224.249 (30 Oct 2002 21:42:14 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 30 Oct 2002 21:42:14 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1870bN-00069c-00 for ; Wed, 30 Oct 2002 22:42:13 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 1870ap-0001kw-00; Wed, 30 Oct 2002 16:41:39 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.uchicago.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!sccrnsc01.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 45 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-NNTP-Posting-Host: 12.228.27.239 Original-X-Complaints-To: abuse@attbi.com Original-X-Trace: sccrnsc01 1036013821 12.228.27.239 (Wed, 30 Oct 2002 21:37:01 GMT) Original-NNTP-Posting-Date: Wed, 30 Oct 2002 21:37:01 GMT Original-Xref: shelby.stanford.edu gnu.emacs.help:106592 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:3142 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:3142 Michael Slass writes: >Friedrich Dominicus writes: > >>Michael Slass writes: >> >>> >>> 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 and , inclusive." >>> (interactive "bPurge html test sections in buffer: ") >>> (save-excursion >>> (save-restriction >>> (goto-char (point-min)) >>> (while (re-search-forward "" nil t) >>> (let ((beg (match-beginning 0)) >>> (end (progn (re-search-forward "" nil t) >>> (match-end 0)))) >>> (if end >>> (kill-region beg end) >>> (error "Unmatched \"\" sequence at position %d" beg))))))) >>However a really nice solution anyway I think there is a problem with >>the end stuff. >> >>The info pages say: >> Search forward from point for regular expression REGEXP. >> Set point to the end of the occurrence found, and return point. >> >>That means you will return the End tags too, There *is* a problem with the end -- the (progn ...) should be (and ...) so that end will be nil if the ending tag isn't found. I forgot that (match-end) would keep the value of the last successful match. (let ((beg (match-beginning 0)) (end (and (re-search-forward "" nil t) (match-end 0)))) -- Mike Slass