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\dDigit [0-9]\DNon-digit [^0-9]\wWord character [a-zA-Z0-9_]\WNon-word character [^a-zA-Z0-9_]\sWhitespace [ \t\n\r\f\v]\SNon-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\1Backreference to group 1\k<name>Named backreferenceLookarounds
(?=pattern)Positive lookahead(?!pattern)Negative lookahead(?<=pattern)Positive lookbehind(?<!pattern)Negative lookbehindFlags/Modifiers
gGlobal - find all matchesiCase insensitivemMultiline - ^ and $ match line breakssDot matches newlineuUnicode modeySticky - 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
\nNewline\rCarriage return\tTab\vVertical tab\fForm feed\0Null character\xHHHex character\uHHHHUnicode character\u{HHHHH}Unicode code point