Regex Reference Cheatsheet

If you are trying to make sense of a regex or want a go to regex reference
Tags : regex

Match Characters
Match digit
/[0-9]/

Match lowercase letter
/[a-z]/

Match uppercase letter
/[A-Z]/ 

Match alphanumeric
/[a-zA-Z0-9]/

Match exceptions
/[^abcd]/

Match one
/[0-9]{1}/

/\d/   digit
/\D/   non-digit
/\w/   word character (a-z, A-Z, 0-9, _)
/\W/   non-word character
/\s/   any white space character \r, \n, \t, \f (form feed)
/\S/   non-white space character
Wildcards
Match all characters but new line
/h.llo/

Match any character 0 or more times
/h.*llo/

Match "b" 0 or more times
/ab*c/

Match 1 or more times
/h.+llo/

Match "b" 1 or more times
/ab+c/
Repeats
Match "repeat" 3 times
/(repeat){3}/

Match "repeat" 1 to 3 times
/(repeat){1,3}/

Match "repeat" at least 3 times
/(repeat){3,}/

3 or more "t" - example "repeattt"
/repeat{3}/
Conditions
/(one|of|these)/

/(maybe)?/

Positive lookahead, matches "a" before "bc"
/a(?=bc)/

Negative lookahead, matches a "a" that is not before expr "bc"
/a(?!bc)/

Positive lookbehind, matches "bc" after "a"
/(?<=a)bc/

Negative lookbehind, matches "bc" that is not after "a"
/(?<!a)bc/