From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bruno Barbier Newsgroups: gmane.emacs.help Subject: Re: Matching labels with buttons Date: Mon, 15 Jul 2024 13:57:55 +0200 Message-ID: <66950ec4.df0a0220.b86df.5c24@mx.google.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6755"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Heime via Users list for the GNU Emacs text editor To: Heime , Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 15 13:58:20 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sTKLU-0001Wm-5I for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 15 Jul 2024 13:58:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTKLD-0000JW-E7; Mon, 15 Jul 2024 07:58:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTKLC-0000JK-91 for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 07:58:02 -0400 Original-Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sTKLA-0007d5-NB for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 07:58:02 -0400 Original-Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2eede876fccso26804701fa.1 for ; Mon, 15 Jul 2024 04:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721044678; x=1721649478; darn=gnu.org; h=mime-version:date:references:in-reply-to:subject:cc:to:from :message-id:from:to:cc:subject:date:message-id:reply-to; bh=dEWlyHcMWvmB3L3fLHGUDEa5vwlQLKlqv9ctqFcFfrc=; b=co08n2UyD2mZ8fCw+LTChnMyoLimEZ3IDSGQEQlKkloEfHbrMsdukJwHAEjxte/YmP 4Nl/8T5PK5rQxvmng33jCjN7wkb0nid9pXR7pb9eUdNKrSNc12KHTrMuBfluASBO0yHE WGId8u64QIfaN0uc7KRgXRNypf+gzn0vlQFudykyRU0whD4oRA+HfXIQrQVxRHb2WSS/ tVNmJfnIfRQPKZ5+IY2qT9Ei9OSiYgFDuOZIwcCSJe79LxISrKLmQSJtvqTNQr/vgdyy q3diV6AV0FXX98kesKfubwjcFkeBmMqazTXd+w1wrcxILpg7dzawtgjNdHrMLn1Gy6J2 +/0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721044678; x=1721649478; h=mime-version:date:references:in-reply-to:subject:cc:to:from :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dEWlyHcMWvmB3L3fLHGUDEa5vwlQLKlqv9ctqFcFfrc=; b=awr8X5cNA9q4Q3XA+PUNzWeeglHtuVjhFcifzw5eziDhtc7FHqw2vL2U3N06VUNZl/ 5PRB+GnVfLyqWiPx4/Uuh8mpy24nM7Qv2uufVLLQP1kxms9UJyZJnQ8ky67kxdJhC3PZ fqK69o6ef8VayO2i7fiXPNNr11FZd8QQlS1VvmLKdpxfjNl23BKq8Jfqzm7aXOFc1pPM T1Aecw8jTPfR32gKePsamSataiMuxgrZSr7ivtiRwIOFt1yy3kSJGaK++4jeohZY6eBo QsJZuUGQVoto/s+NImmDteRwupMBQ37X/IBVG6QCbdF56nwmoHj6YWtCM/BPbwz1DX7W ui2w== X-Gm-Message-State: AOJu0Yxrp5V2DtASOBSnlhC6yRBvxijDF+Wtxb39AZQLmz8Gn8J2JLQy cmzbIZe2x7MWJYGwFazzyHNyGTY3KCD0FZRXH7KUT5vcnLogrNIm X-Google-Smtp-Source: AGHT+IFNqUdS7aHjIvc165wXz4kczcwnwFvRItssnYP2e66leGDFeiJAzvbEyFRT4QcPelSfgmF7yw== X-Received: by 2002:a2e:9dd3:0:b0:2ee:8777:f86a with SMTP id 38308e7fff4ca-2eeb3188d1cmr122443911fa.37.1721044677381; Mon, 15 Jul 2024 04:57:57 -0700 (PDT) Original-Received: from keynux.home.arpa. ([2a01:e0a:505:3460:1c18:688d:ece4:372e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3680daccc9csm6179865f8f.57.2024.07.15.04.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 04:57:56 -0700 (PDT) Original-Received: by keynux.home.arpa. (sSMTP sendmail emulation); Mon, 15 Jul 2024 13:57:55 +0200 In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::235; envelope-from=brubar.cs@gmail.com; helo=mail-lj1-x235.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:147218 Archived-At: Heime writes: > Sent with Proton Mail secure email. > > On Monday, July 15th, 2024 at 11:17 PM, Heime 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 Because it does match: (string-match "\\(\\s-*\\[\\-\\]\\s-*\\)\\(.*\\)" "OFF [-]") => 3 When building regular expressions, I'm often using the amazing M-x re-builder: it allows to construct regexps interactively with visual feedbacks, it even understands the "rx" syntax, for more readable regexps. HTH, Bruno