help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use the characters "+" and "-" in regular expressions


From: Marcin Borkowski
Subject: Re: Use the characters "+" and "-" in regular expressions
Date: Wed, 19 May 2021 19:43:14 +0200
User-agent: mu4e 1.1.0; emacs 28.0.50

On 2021-05-19, at 18:39, Skip Montanaro <skip.montanaro@gmail.com> wrote:

>> > 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

And except the caret right after the `['.

> the special cases from N to 1.

So, N to 2.  (Still a win, though.)

Best,

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]