[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 18:27:45 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Wed, May 19, 2021 at 11:17:34AM -0500, Skip Montanaro wrote:
> > Is there a way to use the character "+" and "-" in regular expressions?
Plus "+" is special. Minus "-" is not.
> Yes, use character sets, e.g. [+] and [-]. If more characters are in a set
> along with a hyphen, that hyphen needs to be the first element of the set
> so as not to be interpreted as defining a range of characters. So, the
> character set containing 0, 9 and hyphen is [-09] or [-90], not [0-9],
> which would include all digits between 0 and 9, but not the hyphen.
Or escape with backslash. Note that due to string syntax you need
two of them.
Besides, the '-' isn't a special character in regexps (except whithin
brackets), so your bracket trick is rather counter-productive. Just
use as-is (except in brackets, where it should, as you say, go last,
to distinguish it from a range marker).
(string-match "-" "Viala-du-Tarn")
=> 5
Cheers
- t
signature.asc
Description: Digital signature
- Re: [External] : Use the characters "+" and "-" in regular expressions, (continued)
- Re: [External] : Use the characters "+" and "-" in regular expressions, Jean Louis, 2021/05/21
- Re: [External] : Use the characters "+" and "-" in regular expressions, Jean Louis, 2021/05/20
- Dash in regexp character classes: Beginnig vs. end [was: Use the characters "+" and "-" in regular expressions], address@hidden, 2021/05/20
- Re: Dash in regexp character classes: Beginnig vs. end [was: Use the characters "+" and "-" in regular expressions], Robert Pluim, 2021/05/20
- RE: [External] : Re: Use the characters "+" and "-" in regular expressions, Drew Adams, 2021/05/19
- RE: [External] : Re: Use the characters "+" and "-" in regular expressions, Drew Adams, 2021/05/19
Re: Use the characters "+" and "-" in regular expressions,
tomas <=
RE: [External] : Use the characters "+" and "-" in regular expressions, Drew Adams, 2021/05/19