Capital letter flips the meaning
Every shorthand has a capital-letter inverse:
\D— NOT a digit. Same as[^\d].\W— NOT a word character. Same as[^\w].\S— NOT whitespace. Same as[^\s].
That's the whole rule. Lowercase = the set, uppercase = the complement.
Real-world uses
\D+ is great for splitting: re.split(r'\D+', '2026-05-04') gives ['2026', '05', '04']. The non-digits between are eaten as the delimiter.
\S+ is a clean way to grab "runs of non-whitespace" — tokens, URLs, file paths.
\W is useful for finding word boundaries you control more tightly than \b can express.
Same Unicode caveats apply
Whatever flavor / flag controls the lowercase form controls the uppercase too. Python 3 default makes \D exclude every Unicode digit, not just ASCII 0-9.