[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [External] : Use the characters "+" and "-" in regular expressions
From: |
Drew Adams |
Subject: |
RE: [External] : Use the characters "+" and "-" in regular expressions |
Date: |
Wed, 19 May 2021 19:17:08 +0000 |
> Is there a way to use the character "+" and "-" in regular expressions?
Ask Emacs!
1. `C-h i' Choose Elisp manual.
2. `i regexp TAB', and complete to
`regexp, special characters in'
3. Read about `\':
it quotes the special characters
Because ‘\’ quotes special characters, ‘\$’ is a
regular expression that matches only ‘$’, and ‘\[’ is
a regular expression that matches only ‘[’, and so on.
IOW, `\+' and `\-' match (only) `+' and `-', respectively.
Another way to match special chars literally is to include
them in a character alternative, also described in the same
page of the manual.
`[+]' matches only `+', `[-]' matches only `+' or `-', and
`[-+]' and `[+-]' match either `+' or `-'.
Note too that `-' in a char alternative behaves specially:
To include a ‘-’, write ‘-’ as the first or last
character of the character alternative, or as the
upper bound of a range. Thus, ‘[]-]’ matches both
‘]’ and ‘-’.
In `[-+]' and `[+-]', the `-' is the first or last char in
the alternative.
Re: Use the characters "+" and "-" in regular expressions, tomas, 2021/05/19
RE: [External] : Use the characters "+" and "-" in regular expressions,
Drew Adams <=