Regex Cheat Sheet - JavaScript
A comprehensive guide to regular expressions with patterns, examples, and explanations
Basic Metacharacters
.
Any character except newline\
Escape character|
Alternation (OR)^
Start of string/line$
End of string/lineCharacter Classes
[abc]
Any of a, b, or c[^abc]
Not a, b, or c[a-z]
Range from a to z[a-zA-Z0-9]
Alphanumeric characters\d
Digit [0-9]\D
Non-digit [^0-9]\w
Word character [a-zA-Z0-9_]\W
Non-word character [^a-zA-Z0-9_]\s
Whitespace [ \t\n\r\f\v]\S
Non-whitespace [^ \t\n\r\f\v]Quantifiers
*
0 or more+
1 or more?
0 or 1{n}
Exactly n times{n,}
n or more times{n,m}
Between n and m times*?
Non-greedy 0 or more+?
Non-greedy 1 or more??
Non-greedy 0 or 1{n,m}?
Non-greedy rangeGroups and Capturing
(pattern)
Capturing group(?:pattern)
Non-capturing group(?<name>pattern)
Named capturing group\1
Backreference to group 1\k<name>
Named backreferenceLookarounds
(?=pattern)
Positive lookahead(?!pattern)
Negative lookahead(?<=pattern)
Positive lookbehind(?<!pattern)
Negative lookbehindFlags/Modifiers
g
Global - find all matchesi
Case insensitivem
Multiline - ^ and $ match line breakss
Dot matches newlineu
Unicode modey
Sticky - match from lastIndexUnicode Properties (with u flag)
\p{L}
Any letter\p{N}
Any number\p{P}
Any punctuation\p{S}
Any symbol\p{Ll}
Lowercase letter\p{Lu}
Uppercase letter\p{Script=Latin}
Latin script characters\P{L}
Not a letter (negated)Escape Sequences
\n
Newline\r
Carriage return\t
Tab\v
Vertical tab\f
Form feed\0
Null character\xHH
Hex character\uHHHH
Unicode character\u{HHHHH}
Unicode code point