Skip to main content

Regex

// Character class
[xyz] => matches one of [x,y,z]
[a-c] => matches one of [a,b,c]

// Negated character class
[^xyz] => matches anything that is not in [x,y,z]
[^a-c] => matches anything that is not in [a,b,c]

// Wildcard
. => matches any single character except line terminators: \n, \r, \u2028 or \u2029

// Digit character
\d     => matches any digit, equivalent to the following
[0-9]  => matches any digit

// Non-digit character
\D     => matches any non-digit, equivalent to the following
[^0-9] => matches any non-digit

// word character class escaple:
\w           => any alphanumeric, including underscore, equivalent to the following
[A-Za-z0-9_] => alphanumeric, including underscore

// Non-word character:
\W
[^A-Za-z0-9_]

// White space character:
\s  => single character, one of space, tab, form feed, line feed, and other unicode spaces

// Non white space character:
\S

// others:
\t         => a tab
\r         => a carriage return
\n         => a linefeed / newline
\v         => a vertical tab
\f         => a form feed
[\b]       => a backspace
\0         => a NULL
\cX        => a control character
\xhh       => matches the character with the code hh (two hexadecimal digits)
\uhhhh     => matches a UTF-16 code-unit with the value hhhh (four hexadecimal digits)
\u{hhhh} or \u{hhhhh} => matches the character with the unicode value U+hhhh or U+hhhhh (hexadecimal digits)



for more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Cheatsheet