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 14:52:24 +0200 Message-ID: <87msmig6lz.fsf@rub.de> References: <87r0bug978.fsf@rub.de> 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="11566"; 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 14:53:12 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 1sTLCa-0002ji-AZ for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 15 Jul 2024 14:53:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTLBv-0005mi-Uk; Mon, 15 Jul 2024 08:52:31 -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 1sTLBu-0005fC-0y for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 08:52:30 -0400 Original-Received: from mout.gmx.net ([212.227.15.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTLBr-0005vd-NT for help-gnu-emacs@gnu.org; Mon, 15 Jul 2024 08:52:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1721047945; x=1721652745; i=stephen.berman@gmx.net; bh=xjTZpjqd7NaqMKcbcUkZT8Z/RoLjm3X3ze0MYMt5gVo=; 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=NRXlmOB11Yt6psDVXq5A0gXTzlQdDMmu5wHsGBazbdmhM0tMl8yi2Qk/AF2pXxZa 8y2gvMhT19IvTO+EjW4dTBmnjHIH0J0+MHP+ABV5/6S5E2lBHk95tx/IuJHrKF/rT ky+WJp9bIm9waEaORGuhdRNoZL9kl9tKiP/Huvmkja+ct3f6GtchU41VQrClNK5Ss JRAmGSaPT8aBPWM+yFvc9QgBhcdMNuaftW4J62/GkIK7Qka7Iri/piZjcw8EXzIEP HpSpIqnYI2zb7qYv/Z9RJo1vlWMh+gnMGpmeH+RPFTBx+7NcGhKSD2KkLI0l3axYb MMI4FepMVnWJyc1TCA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([88.130.50.244]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MS3mz-1swJ0d3Srz-00KXK4; Mon, 15 Jul 2024 14:52:24 +0200 In-Reply-To: (Heime's message of "Mon, 15 Jul 2024 12:35:53 +0000") X-Provags-ID: V03:K1:QFbUlzkoCguGh+Q3edE+Krdf/DiOBANDXaRSST6aOWj+gh7jvv6 vrlPl/1qe1MZRjbEIdMH2eTjI41mcLCL5FmRGmhz15sNIHO1LmBSgnW0DYOtjSXhVxmfej4 gv63zDZmj7lyW5plwFplGY6e8cWTuoIcjjbU1D6j7X060qJanCq2gPJy0y5oYpmFIXCD4p9 +qldv436zwW6TWduZm1JA== UI-OutboundReport: notjunk:1;M01:P0:lEFzhJ4mqPY=;QKHaM6Aq74iAWtliGYA5VArEO5p l5XJFWHuJpqpnzD2z9ZrshmqDAXwmf8QDZgzNpR7xwdZsku+Fx/I5xBD+AgN4Kcba1UKyPmkz Z2+zp9+uOPnA18gTVS79osYbwQpnrx4phFLW9LC4AsHKX1zySXFrCzCS7dgfcgXOlH65fK6Ry 8zi5r3jII7s60KQn0EClNRSh5fGcZRiRGBG1+v7YCVWn4//JM/a3+a8oJIIoi4cOwfvYiOUrG bWv57Q4+OiuT68SG3Psf2Jg3Jmk5qBbgbIAIs6ZFlGoPaKjqsSDvbjGvgUZrBOZfdTOSRHvFP HHyOOPbbSD/3Bq6g5wz0n20VMiHO+DhXmNXsvX3MtHzzW/FnOZCGHSmiFj4bs1uFtXtVqtzze vLvQnHxC/D4jHQ3BHCfMiTQNdG4o3xmf6z1tX6zYvnRffX0h/L4YeAzYO75gSWaVy5TzKMvfW 6lMWVaYUGYjmkiM5uMSvGhujJzBzovAZt6hvAu3zWFdLzvZafnp/fWC0PJmnCSC3bX1yHoWjk baU+VUVpAGIURNm2wW3HWytD93QrgcUULZbKVmdGlqGlx5mXHVmVDdkkaqnEEOfX4VEE3mCO1 cna3DblmlaNHz23QvyuuNhj4l9QO78xN5ozSkVogYJz1ciKTbc/iPPa9fajIA3ZSMG5msKNKT sNST0PbH2RcJ+xUGUS/4AmdkIxSQtSDyfbdHYSEApvSzGaRm1cKc3r/uB/Plub/iROqViLlTC adnaPEzgFBNSIfX+AxFhCzpbGUihl6m6e293kF5lUSDRrX/S3HudNPrmEWyG3mQKiBsgZdQL Received-SPF: pass client-ip=212.227.15.18; 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_H4=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:147220 Archived-At: On Mon, 15 Jul 2024 12:35:53 +0000 Heime wrot= e: > On Monday, July 15th, 2024 at 11:56 PM, Stephen Berman > wrote: > >> On Mon, 15 Jul 2024 11:25:28 +0000 Heime heimeborgia@protonmail.com wro= te: >> >> > 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 ab= ove >> > > >> > > "\\(.\\)\\(\\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 strin= g >> being matched against; see (info "(elisp) Regexp Backslash"). >> >> Steve Berman > > > I would like to have two regex expressions, one to match only " [-] LABE= L " 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