[Top][All Lists]

[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:50:37 GMT
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Friedrich Dominicus <> writes:

>Michael Slass <> writes:
>> I think a lisp program would do better at 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
>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. 


Your point about the re-search is well-taken; just search-forward
would be better.

The flexibilty of your solution which lets the user choose the start
and end tags is balanced against the convenience of my solution where
he doesn't have to type that information in.

My function doesn't have a meaningful return value, so I'm not sure
what your question is.  If you're concerned that I'm not setting beg
or end correctly, please note that they are set to the return value of
the functions (match-beginning 0) and (match-end 0) which behave as
you'd imagine from the names.

I think the OP wanted the tags killed, as well as all the stuff
inbetween them, but if that's not so, switching the (match-end 0) and
the (match-beginning 0) in the defun will fix that.

Mike Slass

reply via email to

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