In shell scripting we have \t for tab , \s for whitespace , \w for word.
What are \W (capital W) and \D (capital D)
used for ?
Asked
Active
Viewed 2,988 times
2
![](../../users/profiles/3832970.webp)
Wiktor Stribiżew
- 484,719
- 26
- 302
- 397
![](../../users/profiles/1468315.webp)
XYZ_Linux
- 2,527
- 5
- 23
- 32
2 Answers
8
\W
is the opposite of \w
and \D
is the opposite of \d
.
It's just like \S
is the opposite of \s
.
\W
and \D
respectively will match what \w
and \d
respectively don't match.
You can have a look at this site for some more explanation.
\w
typically matches [A-Za-z0-9_]
(ignoring the foreign characters)
\W
thus matches [^A-Za-z0-9_]
And since
\d
typically matches [0-9]
(ignoring the foreign digits)
\D
thus matches [^0-9]
![](../../users/profiles/1578604.webp)
Jerry
- 67,172
- 12
- 92
- 128
-
1This answer has been added to the [Stack Overflow Regular Expression FAQ](http://stackoverflow.com/a/22944075/2736496), under "Character Classes". – aliteralmind Apr 10 '14 at 00:19
6
According to the manual:
\W Match a non-word character
\D Match a non-digit character
\W
matches any character that is not matched by \w
. Likewise \D
matches any character that is not matched by \d
.
![](../../users/profiles/445221.webp)
konsolebox
- 60,986
- 9
- 83
- 94