[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Use the characters "+" and "-" in regular expressions
From: |
tomas |
Subject: |
Re: Use the characters "+" and "-" in regular expressions |
Date: |
Wed, 19 May 2021 23:32:07 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Thu, May 20, 2021 at 02:30:22AM +0700, Yuri Khan wrote:
> 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.
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’t need 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
signature.asc
Description: Digital signature
- 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, 2021/05/19
- Re: Use the characters "+" and "-" in regular expressions,
tomas <=
- 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
- Re: [External] : Use the characters "+" and "-" in regular expressions, steve-humphreys, 2021/05/20