From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Use the characters "+" and "-" in regular expressions Date: Wed, 19 May 2021 23:32:07 +0200 Message-ID: <20210519213207.GD4855@tuxteam.de> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="n2Pv11Ogg/Ox8ay5" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12398"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.5.21 (2010-09-15) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 19 23:32:46 2021 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 1ljTo4-00032D-VL for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 19 May 2021 23:32:44 +0200 Original-Received: from localhost ([::1]:36418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljTo3-00051E-Rd for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 19 May 2021 17:32:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljTnY-00050u-5G for help-gnu-emacs@gnu.org; Wed, 19 May 2021 17:32:12 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:36213) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1ljTnV-0004CC-Pz for help-gnu-emacs@gnu.org; Wed, 19 May 2021 17:32:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:To:Date; bh=mj65H1SMzUlj3UFyuDrtiIRYu2wCbRSqsgKfvLXp0sE=; b=U+xGJkJZq9A1pvgVkNqZK+5V/+ruwwFT8AxEWWCWKB0i4+rQhUWyEJ2xYCRFkp7N0D4tQ1i1j/bh6Y1wjuKBYWqekCJAqaBSp9HT1LBqD7+L8Wyf3Pi8x36FjbiB4S/drgBcOuc1A8sC99Y+6W0KHGmPh8a/eoV0BATNwT+2M++Cn2ExIHFOZ2hKrYfOC1HB0zMgXJpDxtcaLUDwxIxNBLcIryBOTlgVbw2hlc2ViLPeSG3Dy3IkzgfSufDR34/W30lbdgKJtp3pYlZICwQVNRUhJ/KqINzd8clMOXQAur0lJZ5r5pFQcpci5SOsG3K+rylvKusMPhK8XSzSQICmWQ==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1ljTnT-0002k8-5T for help-gnu-emacs@gnu.org; Wed, 19 May 2021 23:32:07 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de 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, 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.23 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" Xref: news.gmane.io gmane.emacs.help:129945 Archived-At: --n2Pv11Ogg/Ox8ay5 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, May 20, 2021 at 02:30:22AM +0700, Yuri Khan wrote: > On Thu, 20 May 2021 at 00:39, wrote: > > > > I had tried > > > > (string-match " [-\+\.]+" s) >=20 > This ought to work, even though you=E2=80=99re using backslashes incorrec= tly. Hm. According to the docs, the dash should go last, but a test actually confirms that it works in first position. OTOH, the regex(7) man page says "first or last" position. Since the underlying lib is probably the same, I'd guess that this is an omission in the Emacs doc. > * + and . are not special inside a character class; you don=E2=80=99t nee= d to > escape them. Exactly. > * If you wanted to escape them in a regexp that is inside a string, > you should have put two backslashes. > > * Escaping them with a single backslash only acts on the string syntax > level; because + and . are not special in a string, they pass through > as themselves so the regexp is the same as if you had written " > [-+.]+". So, as seen by the regexp they weren't escaped anyway ;-) Cheers - t --n2Pv11Ogg/Ox8ay5 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAmClg9cACgkQBcgs9XrR2kYhcgCfRCgnePilwA/dPey7GNB4dqGI cuUAnR4UZ5NV8xNfPCSNLnCOQfNGvFHq =e/Mg -----END PGP SIGNATURE----- --n2Pv11Ogg/Ox8ay5--