Character Classes
Character classes match one character from a defined set. Square brackets [...] define a custom class; shorthand classes like \d, \w, \s match common types.
Character classes match one character from a defined set. Square brackets [...] define a custom class; shorthand classes like \d, \w, \s match common types.
/[aeiou]/i // Any vowel
/[a-z]/ // Lowercase letter
/[A-Za-z0-9]/ // Alphanumeric
/[^0-9]/ // NOT a digit (negated class)
// Shorthand classes
/\d/ // Digit [0-9]
/\D/ // Non-digit
/\w/ // Word char [A-Za-z0-9_]
/\W/ // Non-word char
/\s/ // Whitespace
/\S/ // Non-whitespace
Negated classes [^...] match any character NOT in the set — useful for validating allowed character sets.
More in JavaScript