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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie regexp question


From: Friedrich Dominicus
Subject: Re: Newbie regexp question
Date: 30 Oct 2002 18:42:36 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp)

Michael Slass <address@hidden> 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)))))))
Well this code is better in some areas, but Mike you missed a big
opportunity ;-) To let the user choose what the tags are and as
mentioned before regular expressions are overkill if you know your
data.

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, if I got that right,
which is not sure I'm a tired and had an unpleasant quarrel with
someone I really appriciate. 

So good night
Friedrich


reply via email to

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