Regex
Character Classes
Match sets and ranges of characters.
By EZ4Code Team
character-classshorthand
Code
[abc] any of a, b, c
[^abc] none of a, b, c
[a-z] range a to z
[A-Z0-9] uppercase letter or digit
\d digit [0-9]
\D non-digit
\w word char [A-Za-z0-9_]
\W non-word char
\s whitespace
\S non-whitespace
. any char except newlineExplanation
Character classes match a single character from a set, with ranges like a-z and negation via a leading caret. Shorthand escapes such as \d, \w, and \s are built-in classes for digits, word characters, and whitespace, with uppercase variants meaning their complement. The dot matches any character except a newline unless the dotall flag is set.