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

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

Re: Matching labels with buttons


From: Heime
Subject: Re: Matching labels with buttons
Date: Mon, 15 Jul 2024 11:25:28 +0000





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



reply via email to

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