From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Matching labels with buttons Date: Mon, 15 Jul 2024 13:56:27 +0200 Message-ID: <87r0bug978.fsf@rub.de> References: Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="607"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 15 13:57:14 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 1sTKKO-000AQo-F4 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 15 Jul 2024 13:57:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTKJs-0008Kh-Ek; Mon, 15 Jul 2024 07:56:40 -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 1sTKJo-0008Ii-5Y for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 07:56:36 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTKJk-0007HR-Re for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 07:56:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1721044588; x=1721649388; i=stephen.berman@gmx.net; bh=R+BqojuZ5Polh7ymgimRnEM5ADvZ6vAwR67u2QL4yYM=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=XfhkS+SML9LvKxpJFKfP/WZYI6CWdCL6T0MBlBkTYLm/K9sP2WbN9olDlaGKY2VZ Gk9wfTmmUz1eHPR56xAw56f8O4M8ouOFBQM/WbRk+Bw88XI82li+jHJkuYqoTGZ6f N9Y63ujIc9r0EVY634qdHFEEAZE+vHuiLqT3FS/jas+6IKMZCx0GptFGuYqR1oKSm +1NVJ9vLPGrcdOce4UWQHXz4sOF0bnQlGzHk5Uvz8vFy2fve0e73RoY0i2Bw6vsHx PsE0xhGwrXhZ1hIA0t9kjGcFDr/CJi53+6hcwr7KTz12Rxyt0+SZsOk2vrYNoRAdx Xj9mQxJIaArVSzTMNg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([88.130.50.244]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N0X8u-1s6RoW0AuS-014kJ7; Mon, 15 Jul 2024 13:56:28 +0200 In-Reply-To: (Heime's message of "Mon, 15 Jul 2024 11:25:28 +0000") X-Provags-ID: V03:K1:oaYzf4HyI1VDyRPUcdog0If62xKYD0e0cm4ZD+SsgYhilGxOl2g eHjEaWLvblYGi6JbHR5GlkJgZSUpXUHfRl5QGO56PqT0o7hTzC/BQbgF0PncHWLpMlvG3Cx nbqLTqJUF/UuOOaIyQa7p/olyasYPMvpHV+dhKVKRTftcxlOzH5joQCSDSQgXAazm7dZrjp 5O0c0PlYtpvudoOzDKsdw== UI-OutboundReport: notjunk:1;M01:P0:C2SEIdI68ZM=;okdxIAo/SOyii6hOT1VdpDYCJBN fX/Mr7lsdF+/n1HhPGc2L83B3ke0ouuv181PTAIQ3Z5BDA3xLRh2L/r7ejNssqtnSdVTb171d Vux6ldTNemRXtLLAyliKN/trgpKZ1Q9ra09OxPpOIhRTLR7e2Bjy4f/eW1ZYBfNQ57cB7hjf2 DQZoFpSZAkq/6/m8Gh7/fn5GNgSaYwPgKr9WgMwCnQ6VWl6Z5gmpH6LG0pBiBSIaXtsp6vYW6 p1HB4sKH4DKYJOqbCQNmh11ccx2arex+1+wmdjNhdEejPMOKvCHwT/izDfRqOK/zJM9HMpPAK 7n+Tmv0kiBMS2g77VRBz1TffnpfN5ZdpWrzFJdlWNnglsOEo168/lp/HLhUWVt+tNxuQuLlc6 /hkmqgF2FK88qMGHH9wokCtBFsvNeLpeLUHFmfTjYe0KwgnUM7El7h2kVnDpr7VteKuzBy2YP Acv5calwefqYJEP23kyOiD8HKPmrtKcEZ0I9NDQcjJUYduHeGP1sOPmahEXLWMD8woOncCYZ7 qo580C8pA6dtgQ4YfZsBAiWo6qKX/mTUQ7S1dOhN8JEOHkqaEnjg5Aj+UeH089Yr9GqLmAirt AVLIOBkJsvRZfazIHhNRiXSXA+3WOEbAibB2fIK2DYCxWifsrtVndJ7H7OEfp3i4cK9z+JsK5 bFMIQYNd5AT0x8HZA6dvVN/VpYWwasAbTEU5NH4VlCY+Uk6OnxW6bF5pUxSb9N2qTSndjoizU HfjAmD3PFnIm1//kf7Z2gKLFC9oE/OyS5XkqDwuj8Yz7tC0/NHoe5xphmT4PHccy39+Au/5Z Received-SPF: pass client-ip=212.227.17.21; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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:147217 Archived-At: On Mon, 15 Jul 2024 11:25:28 +0000 Heime wrot= e: > 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 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