From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Skip Montanaro Newsgroups: gmane.emacs.help Subject: Re: Use the characters "+" and "-" in regular expressions Date: Wed, 19 May 2021 11:39:46 -0500 Message-ID: References: <20210519162745.GJ7028@tuxteam.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4705"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Help Gnu Emacs , steve-humphreys@gmx.com To: tomas@tuxteam.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 19 19:05:43 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 1ljPde-0000vD-1n for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 19 May 2021 19:05:42 +0200 Original-Received: from localhost ([::1]:33134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljPdd-00073g-2C for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 19 May 2021 13:05:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljPF3-0004Tf-IA for help-gnu-emacs@gnu.org; Wed, 19 May 2021 12:40:17 -0400 Original-Received: from mail-yb1-xb31.google.com ([2607:f8b0:4864:20::b31]:44663) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ljPF0-0000QP-Nv for help-gnu-emacs@gnu.org; Wed, 19 May 2021 12:40:17 -0400 Original-Received: by mail-yb1-xb31.google.com with SMTP id y36so2335923ybi.11 for ; Wed, 19 May 2021 09:40:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SdTPOC0/9PfZO6+nVDSlneHu4Je8HHPvWfxr67GlBrY=; b=d16+pYKXq0u8FYQFkjXNIUXatQs9uC3ZyWcelooIBdspui7C2ru3CVQ3j2yoH0LvCI BM2uWMvPEoaX/VbNsRa63ND80zAafc+FHA3S2iHNyb5FwKj2OeUWzw2ad973lqSMpgbH qyx56Tj4xWX2eWCXgtLPI6wHpiLCCuz0yS5l/NkEvpadej59t+7jtO157h9jML5nHseo jDWBZuwQvLltgdPzfSJUzlRaKnoXO2vIIVHdBY9c2vlVcgo7iLyXm8aiqI0ED0DlXovO aSNUcTHad7mCsYDUA8BdHJJRiNVqzuO+xUqBHZWbdYGXp8rGlAV9kUYKMg+m4O/+gxIF 76QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SdTPOC0/9PfZO6+nVDSlneHu4Je8HHPvWfxr67GlBrY=; b=K3YfH5pKyKX7lOYTQkE6gdEYVutFuARCfgDkjGBMuzIqMGm5FqMBMLavQzzvaXODzL ux3bmoFqvzL3UIC2aUJTuoUw9AWbvjeYhfsy12qPQF+FiZSj85S6vOYiBRWBPG0uoH26 5+L2+nI1U7ypDEdebmStfjw/LTu3n0rqpzX0nGHVEzHYCiTfI1LQ0Gu/hg2gK7LORH0+ JKj2pVq4rfZS2HJFTSOmh31FTUxQamm8VHPSPW21ZKrMrzBAMzuXMMMXV3xHoYlHkxzQ Lk1DnGF4b+wmfVxw1Op3yKoLGWYsVNJJQz1pkpNOb7AVC8P73eNLwiQ9zSwFrSzVgfjs NNtA== X-Gm-Message-State: AOAM530Xx42PkHttzfGdxKMwaaGpYqc6+dcfu7lMBKdswY7sJyXCeBh/ gt+gOJrkjovAr7Osu4HFw40zGVHi2Y1OyJKEz6nDDiI= X-Google-Smtp-Source: ABdhPJwygvPWqron+1NRr88/5gODrSAouMU0NQaJmu2ZhOq26KgYrirkn3YQa8V2cIsHKo7wjCxHRrTCzp5hPvwAVOA= X-Received: by 2002:a25:dc4d:: with SMTP id y74mr646884ybe.490.1621442412991; Wed, 19 May 2021 09:40:12 -0700 (PDT) In-Reply-To: <20210519162745.GJ7028@tuxteam.de> Received-SPF: pass client-ip=2607:f8b0:4864:20::b31; envelope-from=skip.montanaro@gmail.com; helo=mail-yb1-xb31.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, 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.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:129934 Archived-At: > > Yes, use character sets, e.g. [+] and [-]. > Plus "+" is special. Minus "-" is not. ... > Or escape with backslash. Note that due to string syntax you need > two of them. Yes, correct you are, Tomas. I long ago got used to putting most punctuation in character sets regardless of its specialness, if for no other reason than to help them stand out when rereading the code later. I also find backslashes ugly (especially within Lisp strings where there is no such thing as a "raw" string such as in Python, so you wind up doubling them). Also, by reflexively putting punctuation in character sets I rarely have to remember which are special, or in what contexts. For example, "$" is special at the end of a regular expression, but not elsewhere. Similarly, "^" is special only at the start. The various special cases just make it kind of tedious and easy to get wrong. By placing punctuation in character sets you declare to the reader, "This is not special, no matter what you might think." Well, except for hyphens inside character sets. :) Still, that reduces the special cases from N to 1. Skip