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

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

Re: Making a regex string that matches (


From: Leo Butler
Subject: Re: Making a regex string that matches (
Date: Fri, 11 Mar 2022 06:24:01 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

goncholden <goncholden@protonmail.com> writes:

> ------- Original Message -------
> On Thursday, March 10th, 2022 at 3:51 PM, Robert Pluim <rpluim@gmail.com> 
> wrote:
>> > > > > > On Thu, 10 Mar 2022 15:39:03 +0100, Emanuel Berg via Users
>> > list for the GNU Emacs text editor help-gnu-emacs@gnu.org said:
>>
>> Emanuel> angelomolina--- via Users list for the GNU Emacs text editor wrote:
>>
>> >> How can I make a regex string if I want to search for (.
>>
>> Emanuel> Uhm ... how much is a 50ยข stamp?

Sarcasm is generally counter-productive.

>
> Have come up with the following function.  Would this be enough to count the 
> number
> oy opening parantheses in a region ?
>
> (defun bracketing-count (region-start region-end)
>   "Counts opening and closing bracketing marks.
> Interactive functions enable them to be called using `M-x`"
>   (interactive "r")  ; gets region start and end
>
>   (message "Counting bracketing marks ...")
>   (save-excursion
>     (let (count)
>       (setq count 0)
>       (goto-char region-start)
>
>       (while (and (< (point) region-end)
>                 (search-forward "\(" region-end t))
>         (setq count (1+ count))) ))))

In addition to other points made, your function doesn't deal with corner
cases, such as

\([(]+\)

Should the count be 1 or 2?

Leo



reply via email to

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