all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Heime <heimeborgia@protonmail.com>
To: Heime <heimeborgia@protonmail.com>
Cc: Stephen Berman <stephen.berman@gmx.net>,
	Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: Matching labels with buttons
Date: Mon, 15 Jul 2024 17:25:42 +0000	[thread overview]
Message-ID: <72n913q3Tv6RlKwXsHxBXRlGEwuYia37iCUcLQg-7S8aHg_qVwE6JhXMRN3wk1IajDCeqvM7QD9yv5EM9yF75G8zwWyPb_VpQAqf_GqasdM=@protonmail.com> (raw)
In-Reply-To: <lobpB45hJUoRe2X-7uDpXL4HuaLpylQOhlqdvMgCknANTqiJwUh7G72d25Z_AmhuxsL2UNUnGfq5iaPKZt-OmXEtGQqKJT8sZt61b9kEH_A=@protonmail.com>

On Tuesday, July 16th, 2024 at 4:24 AM, Heime <heimeborgia@protonmail.com> wrote:

> On Tuesday, July 16th, 2024 at 1:42 AM, Stephen Berman stephen.berman@gmx.net wrote:
> 
> > On Mon, 15 Jul 2024 12:58:05 +0000 Heime heimeborgia@protonmail.com wrote:
> > 
> > > Sent with Proton Mail secure email.
> > > 
> > > On Tuesday, July 16th, 2024 at 12:52 AM, Stephen Berman
> > > stephen.berman@gmx.net wrote:
> > > 
> > > > On Mon, 15 Jul 2024 12:35:53 +0000 Heime heimeborgia@protonmail.com wrote:
> > > > 
> > > > > On Monday, July 15th, 2024 at 11:56 PM, Stephen Berman
> > > > > stephen.berman@gmx.net wrote:
> > > > > 
> > > > > > On Mon, 15 Jul 2024 11:25:28 +0000 Heime heimeborgia@protonmail.com wrote:
> > > > > > 
> > > > > > > Sent with Proton Mail secure email.
> > > > > > > 
> > > > > > > On Monday, July 15th, 2024 at 11:17 PM, Heime
> > > > > > > heimeborgia@protonmail.com wrote:
> > > > > > > 
> > > > > > > > I want to match cases such as
> > > > > > > > 
> > > > > > > > Label [-]
> > > > > > > > 
> > > > > > > > Have constructed the following regexp, but it does not match the above
> > > > > > > > 
> > > > > > > > "\\(.\\)\\(\\s-\\[\\-\\]\\s-\\)"
> > > > > > > > 
> > > > > > > > I aw using
> > > > > > > > 
> > > > > > > > (when (string-match "\\(.\\)\\(\\s-\\[\\-\\]\\s-\\)" text)
> > > > > > > 
> > > > > > > In the code I have
> > > > > > > 
> > > > > > > (if (string-match "\\(\\s-\\[\\-\\]\\s-\\)\\(.*\\)" label) ; [-] LB
> > > > > > > 
> > > > > > > (progn
> > > > > > > (setq bt (match-string 1 label))
> > > > > > > (setq lb (match-string 2 label))
> > > > > > > (setq result
> > > > > > > (concat bt (propertize lb 'face '(:foreground "red")))))
> > > > > > > 
> > > > > > > (when (string-match "\\(.\\)\\(\\s-\\[\\-\\]\\s-*\\)" label) ; LB [-]
> > > > > > > 
> > > > > > > (setq lb (match-string 1 label))
> > > > > > > (setq bt (match-string 2 label))
> > > > > > > (setq result
> > > > > > > (concat (propertize lb 'face '(:foreground "red")) bt)))
> > > > > > > 
> > > > > > > Doing some tests with
> > > > > > > 
> > > > > > > "OFF [-]"
> > > > > > > 
> > > > > > > keeps matching the first string-match
> > > > > > 
> > > > > > That's because your regexp isn't anchored, so string-match succeeds if
> > > > > > it finds a match anywhere in the string passed to it. To avoid this,
> > > > > > start the regexp with "\\`", which anchors it to the start of the string
> > > > > > being matched against; see (info "(elisp) Regexp Backslash").
> > > > > > 
> > > > > > Steve Berman
> > > > > 
> > > > > I would like to have two regex expressions, one to match only " [-] LABEL " and
> > > > > another to match only " LABEL [-] ". With any number of whitespace.
> > > > > 
> > > > > Can one use "^" ? Or is "\\`" preferred ?
> > > > 
> > > > If you are always matching against a string, e.g. just using
> > > > string-match, then IIUC "^" and "\\`" give the same results. If you are matching against test in a buffer, e.g. with re-search-forward, looking-at etc., then they can differ: "^" matches the beginning the the line containing the matched string, "\\\\\\\\\\\\\\\\`" the beginning of the string
> > > > itself, regardless of where in the line it is (at point-min the results
> > > > are the same).
> > > > 
> > > > > And can one use "[[:space:]]" rather
> > > > > than "\\s-" ? Which is preferred ?
> > > > 
> > > > IIUC these both give the same results.
> > > > 
> > > > Steve Berman
> > > 
> > > Would I introduce \\` before the first grouping
> > > 
> > > "\\`\\(\\s-\\[\\-\\]\\s-\\)\\(.*\\)"
> > 
> > Since "\\`" matches the empty string, I don't think it matters whether
> > it's inside or outside of the group. But since in this case it's
> > anchoring the entire regexp, it seems conceptually preferable to keep it
> > outside (in contrast, e.g., to the case where the regexp is a
> > disjunction and you only want to anchor one of the disjuncts).
> > 
> > > How would I print \\` in a docstring ?
> > 
> > You have to escape the "`": \\\\\\\\\\\\\\\\=` (not \\=\\`).
> > 
> > Steve Berman
> 
> I also have to handle the case of " LABEL [-] " with a different regex, so I can
> distinguish between " [-] LABEL " and " LABEL [-] ".

In the latter case I want to match [-] at the end with any trailing spaces.




  reply	other threads:[~2024-07-15 17:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15 11:17 Matching labels with buttons Heime
2024-07-15 11:25 ` Heime
2024-07-15 11:56   ` Stephen Berman
2024-07-15 12:35     ` Heime
2024-07-15 12:52       ` Stephen Berman
2024-07-15 12:58         ` Heime
2024-07-15 13:42           ` Stephen Berman
2024-07-15 16:24             ` Heime
2024-07-15 17:25               ` Heime [this message]
2024-07-15 21:20                 ` Stephen Berman
2024-07-15 21:29                   ` Heime
2024-07-15 21:50                     ` Stephen Berman
2024-07-15 22:29                       ` Heime
2024-07-15 22:46                         ` Stephen Berman
2024-07-15 23:02                           ` Heime
2024-07-15 11:57   ` Bruno Barbier
2024-07-15 18:29     ` tpeplt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='72n913q3Tv6RlKwXsHxBXRlGEwuYia37iCUcLQg-7S8aHg_qVwE6JhXMRN3wk1IajDCeqvM7QD9yv5EM9yF75G8zwWyPb_VpQAqf_GqasdM=@protonmail.com' \
    --to=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=stephen.berman@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.