[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 21:37:01 GMT |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
Michael Slass <miknrene@drizzle.com> writes:
>Friedrich Dominicus <frido@q-software-solutions.com> writes:
>
>>Michael Slass <miknrene@drizzle.com> 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 <!--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)))))))
>>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 "<!--End of Test-->" nil t)
(match-end 0))))
--
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
- RE: Newbie regexp question, Bingham, Jay, 2002/10/30
- RE: Newbie regexp question, Bingham, Jay, 2002/10/30
- Re: Newbie regexp question, Paul Cohen, 2002/10/31
- RE: Newbie regexp question, Bingham, Jay, 2002/10/31