[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
- Use the characters "+" and "-" in regular expressions, steve-humphreys, 2021/05/19
- Re: Use the characters "+" and "-" in regular expressions, Skip Montanaro, 2021/05/19
- Re: Use the characters "+" and "-" in regular expressions, steve-humphreys, 2021/05/19
- Re: Use the characters "+" and "-" in regular expressions,
Yuri Khan <=
- Re: Use the characters "+" and "-" in regular expressions, tomas, 2021/05/19
- RE: [External] : Re: Use the characters "+" and "-" in regular expressions, Drew Adams, 2021/05/19
- Re: RE: [External] : Use the characters "+" and "-" in regular expressions, steve-humphreys, 2021/05/20
- [External] : Use the characters "+" and "-" in regular expressions, steve-humphreys, 2021/05/20
- Re: [External] : Use the characters "+" and "-" in regular expressions, tomas, 2021/05/20
- Re: [External] : Use the characters "+" and "-" in regular expressions, steve-humphreys, 2021/05/20
- [External] : Use the characters "+" and "-" in regular expressions, steve-humphreys, 2021/05/20
- Re: [External] : Use the characters "+" and "-" in regular expressions, tomas, 2021/05/20
- Re: [External] : Use the characters "+" and "-" in regular expressions, steve-humphreys, 2021/05/20
- Re: [External] : Use the characters "+" and "-" in regular expressions, tomas, 2021/05/20