* Making a regex string that matches (
@ 2022-03-10 13:36 angelomolina--- via Users list for the GNU Emacs text editor
2022-03-10 14:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: angelomolina--- via Users list for the GNU Emacs text editor @ 2022-03-10 13:36 UTC (permalink / raw)
To: Help Gnu Emacs
How can I make a regex string if I want to search for (.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Making a regex string that matches (
2022-03-10 13:36 Making a regex string that matches ( angelomolina--- via Users list for the GNU Emacs text editor
@ 2022-03-10 14:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-10 15:51 ` Robert Pluim
2022-03-10 15:13 ` Leo Butler
2022-03-11 23:43 ` Eduardo Ochs
2 siblings, 1 reply; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2022-03-10 14:39 UTC (permalink / raw)
To: help-gnu-emacs
angelomolina--- via Users list for the GNU Emacs text editor wrote:
> How can I make a regex string if I want to search for (.
Uhm ... how much is a 50¢ stamp?
(re-search-forward "(")
(
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Making a regex string that matches (
2022-03-10 14:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2022-03-10 15:51 ` Robert Pluim
2022-03-10 17:14 ` goncholden
0 siblings, 1 reply; 12+ messages in thread
From: Robert Pluim @ 2022-03-10 15:51 UTC (permalink / raw)
To: help-gnu-emacs
>>>>> 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?
Emanuel> (re-search-forward "(")
And since youʼre searching for a literal '(', you can use
`search-forward'.
Robert
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Making a regex string that matches (
2022-03-10 15:51 ` Robert Pluim
@ 2022-03-10 17:14 ` goncholden
2022-03-10 17:48 ` Eric Abrahamsen
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: goncholden @ 2022-03-10 17:14 UTC (permalink / raw)
To: Robert Pluim; +Cc: help-gnu-emacs
------- 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?
>
> Emanuel> (re-search-forward "(")
>
> And since youʼre searching for a literal '(', you can use
>
> `search-forward'.
>
> Robert
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))) ))))
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Making a regex string that matches (
2022-03-10 17:14 ` goncholden
@ 2022-03-10 17:48 ` Eric Abrahamsen
2022-03-10 17:57 ` [External] : " Drew Adams
` (2 subsequent siblings)
3 siblings, 0 replies; 12+ messages in thread
From: Eric Abrahamsen @ 2022-03-10 17:48 UTC (permalink / raw)
To: help-gnu-emacs
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?
>>
>> Emanuel> (re-search-forward "(")
>>
>> And since youʼre searching for a literal '(', you can use
>>
>> `search-forward'.
>>
>> Robert
>
> 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))) ))))
Not to detract from your achievement, but there's already a
`count-matches' function, if you go back to using a regexp.
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [External] : Re: Making a regex string that matches (
2022-03-10 17:14 ` goncholden
2022-03-10 17:48 ` Eric Abrahamsen
@ 2022-03-10 17:57 ` Drew Adams
2022-03-10 18:54 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-10 18:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-11 12:24 ` Leo Butler
3 siblings, 1 reply; 12+ messages in thread
From: Drew Adams @ 2022-03-10 17:57 UTC (permalink / raw)
To: goncholden, Robert Pluim; +Cc: help-gnu-emacs@gnu.org
> 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))) ))))
1. You can just use function `count-matches', with "("
as the regexp.
https://emacs.stackexchange.com/q/70870/105
2. (let (count) (setq count 0)...)
->
(let ((count 0)...)
3. (search-forward "(" ...) ; You don't need "\(".
4. If your user uses your command, s?he sees only the
message "Counting bracketing marks...". She likely
would like to see the count at the end, no?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Making a regex string that matches (
2022-03-10 17:14 ` goncholden
2022-03-10 17:48 ` Eric Abrahamsen
2022-03-10 17:57 ` [External] : " Drew Adams
@ 2022-03-10 18:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-11 12:24 ` Leo Butler
3 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2022-03-10 18:03 UTC (permalink / raw)
To: help-gnu-emacs
goncholden wrote:
> Have come up with the following function. Would this be
> enough to count the number oy opening parantheses in
> a region ? [...]
(how-many "(" (point)) ; 2
((
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Making a regex string that matches (
2022-03-10 17:14 ` goncholden
` (2 preceding siblings ...)
2022-03-10 18:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2022-03-11 12:24 ` Leo Butler
2022-03-11 19:53 ` Emanuel Berg via Users list for the GNU Emacs text editor
3 siblings, 1 reply; 12+ messages in thread
From: Leo Butler @ 2022-03-11 12:24 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Making a regex string that matches (
2022-03-11 12:24 ` Leo Butler
@ 2022-03-11 19:53 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2022-03-11 19:53 UTC (permalink / raw)
To: help-gnu-emacs
Leo Butler wrote:
>>> How can I make a regex string if I want to search for (.
>>
>> Uhm ... how much is a 50¢ stamp?
>
> Sarcasm is generally counter-productive.
It isn't sarcasm, it is a question where the answer is so
obvious you get perplexed thinking there is some other layer
to it ...
And maybe this is what happened to the OP who didn't just try
"(" but instead wrote a bunch of Elisp :)
That has happened to all of us BTW, perhaps this is an extreme
case tho ;)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Making a regex string that matches (
2022-03-10 13:36 Making a regex string that matches ( angelomolina--- via Users list for the GNU Emacs text editor
2022-03-10 14:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2022-03-10 15:13 ` Leo Butler
2022-03-11 23:43 ` Eduardo Ochs
2 siblings, 0 replies; 12+ messages in thread
From: Leo Butler @ 2022-03-10 15:13 UTC (permalink / raw)
To: angelomolina--- via Users list for the GNU Emacs text editor; +Cc: angelomolina
angelomolina--- via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
> How can I make a regex string if I want to search for (.
For interactive use, the key sequence (C=Control, M=Alt/Mod):
C-M s (
For programmatic use, you can use
M-x regexp-builder RET
to start up regexp-builder which will let you build regexps
interactively and show the matches in the buffer where you were
working. You will see that
"("
works.
C-c C-q
deletes the *RE-Builder* window that was created (the buffer remains, so
you can re-use it).
-----
Btw, I noticed that regexp-builder is part of GNU Emacs, but there is no
documentation in the manual. The only documentation is found by looking
at the docstring of the function.
Leo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Making a regex string that matches (
2022-03-10 13:36 Making a regex string that matches ( angelomolina--- via Users list for the GNU Emacs text editor
2022-03-10 14:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-10 15:13 ` Leo Butler
@ 2022-03-11 23:43 ` Eduardo Ochs
2 siblings, 0 replies; 12+ messages in thread
From: Eduardo Ochs @ 2022-03-11 23:43 UTC (permalink / raw)
To: angelomolina; +Cc: Help Gnu Emacs
On Thu, 10 Mar 2022 at 11:31, angelomolina--- via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> How can I make a regex string if I want to search for (.
On Thu, 10 Mar 2022 at 11:31, angelomolina--- via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> How can I make a regex string if I want to search for (.
Hi Angelo,
Slightly off-topic, but I learned a lot about obscure-ish regexp
tricks by using rx and xr to convert regexps to the rx notation and
back... see:
(info "(elisp)Rx Notation")
https://github.com/mattiase/xr
Try:
(rx "/*"
(zero-or-more
(or (not (any "*"))
(seq "*" (not (any "/")))))
(one-or-more "*")
"/")
(xr "/\\*\\(?:[^*]\\|\\*[^/]\\)*\\*+/")
(xr find-function-regexp)
Here are some examples of things that I didn't know how to write in
regexp syntax, and that I only discovered using rx:
(rx (any "[]"))
(rx (any ""))
(rx (not (any "")))
Now let's wait for Emanuel Berg's reaction... =)
Cheers,
Eduardo Ochs
http://angg.twu.net/#eev
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2022-03-11 23:43 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-10 13:36 Making a regex string that matches ( angelomolina--- via Users list for the GNU Emacs text editor
2022-03-10 14:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-10 15:51 ` Robert Pluim
2022-03-10 17:14 ` goncholden
2022-03-10 17:48 ` Eric Abrahamsen
2022-03-10 17:57 ` [External] : " Drew Adams
2022-03-10 18:54 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-10 18:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-11 12:24 ` Leo Butler
2022-03-11 19:53 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-10 15:13 ` Leo Butler
2022-03-11 23:43 ` Eduardo Ochs
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.