🔰character set

🚧 under construction

JSvalueobjectregexpattern ⟩ char set

.	// any non-newline character 
[^]     // any character (including newline) ⭐️

[a-c]   // (ranges) = [abc] = (a|b|c)
[^01]   // invert a set (not 0, not 1 in this case)

\d	// a digit = [0-9] = [0123456789]
\D	// not a digit
\w	// alphanumeric character (“word character”) = [a-zA-Z0-9_]
\W	// nonalphanumeric character
\s	// whitespace (space, tab, newline, ...)
\S	// nonwhitespace

🈯 synonyms: "character class"

Only ^ - \ ] need to be escaped inside a character class.

[.+]	// ".", "+" have NO special meaning in brackets
  • As far as JavaScript’s regular expressions are concerned, a “word character” is only one of A-Z, a-z, 0-9, and _.

  • Things like é or β, will not match \w (and will match \W).

Within square brackets [x-y], a hyphen (-) between two characters can be used to indicate a range of characters, where the ordering is determined by the character’s Unicode number.

Last updated