difference between [a-z]
and [\a-z]
. The first one does not contain space ' '
in the range but the second one is matching for space ' '
. Why??
Asked
Active
Viewed 54 times
-2
![](../../users/profiles/1491895.webp)
Barmar
- 596,455
- 48
- 393
- 495
![](../../users/profiles/9089606.webp)
Kenny Omega
- 338
- 1
- 10
-
Because `\a` = ASCII code 7 – Lucas Trzesniewski Jan 12 '18 at 10:46
-
... and the characters from code 7 to character z (code 122) include the space and other characters. – Andy G Jan 12 '18 at 10:48
-
1One of you should post that as an answer. – Barmar Jan 12 '18 at 10:48
2 Answers
1
[a-z]
matches a character from a
to z
[\a-z]
matches a character from \a
to z
\a
is not a
. According to regex101.com \a matches the bell character (ASCII 7). I don't know what this character is but it looks like whitespace.
![](../../users/profiles/9192146.webp)
JackPRead
- 178
- 8
1
\a
is ASCII code 7 (bell). a-z
would be the range of characters a through z.
So \a-z
is the range of characters from \a
to the character z
(index 122) which includes the space character (and many others).
An ascii table confirms the range of characters covered.
If you wanted to allow for a backslash in addition to the characters a through z, then use [a-z\\]
(the backslash needs to be escaped). [I moved it to the end as I find this version clearer.]
![](../../users/profiles/620444.webp)
Andy G
- 18,518
- 5
- 42
- 63