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: Yuri Khan
Subject: Re: Use the characters "+" and "-" in regular expressions
Date: Thu, 20 May 2021 02:30:22 +0700

On Thu, 20 May 2021 at 00:39, <steve-humphreys@gmx.com> wrote:
>
> I had tried
>
> (string-match " [-\+\.]+" s)

This ought to work, even though you’re using backslashes incorrectly.

* + and . are not special inside a character class; you don’t need to
escape them.
* 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 "
[-+.]+".


(string-match " [-+.]+" ";; ----")
⇒ 2
(string-match " [-+.]+" ";; ++++")
⇒ 2
(string-match " [-+.]+" ";; ....")
⇒ 2
(string-match " [-+.]+" ";; -+-+")
⇒ 2



reply via email to

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