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 7,799 times
6

Wiktor Stribiżew
- 607,720
- 39
- 448
- 563

XYZ_Linux
- 3,247
- 5
- 31
- 34
2 Answers
15
\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]

Jerry
- 70,495
- 13
- 100
- 144
-
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
.

konsolebox
- 72,135
- 12
- 99
- 105