Regex Cheatsheet
A clean searchable reference of regex syntax with copyable examples.
Anchors
^Start of string (or line in m mode)$End of string (or line in m mode)\bWord boundary\BNon-word boundaryCharacter classes
.Any character except newline\dDigit (0-9)\DNon-digit\wWord character (a-z, A-Z, 0-9, _)\WNon-word character\sWhitespace\SNon-whitespace[abc]Any of a, b, or c[^abc]Not a, b, or c[a-z]Range a through zQuantifiers
*0 or more (greedy)+1 or more (greedy)?0 or 1{n}Exactly n{n,}n or more{n,m}Between n and m*?0+ (lazy)+?1+ (lazy)Groups & references
(...)Capturing group(?:...)Non-capturing group(?<name>...)Named capturing group\1, \2Backreference to group\k<name>Backreference to named groupLookarounds
(?=...)Positive lookahead(?!...)Negative lookahead(?<=...)Positive lookbehind(?<!...)Negative lookbehindFlags
gGlobal - find all matchesiCase-insensitivemMultiline - ^ and $ match line boundariessDotall - . matches newlineuUnicode modeySticky - match at lastIndex onlyCommon patterns
^[\w.+-]+@[\w-]+\.[\w.-]+$Email (pragmatic)^https?://\S+$URL (http or https)^\d{3}-?\d{3}-?\d{4}$US phone^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ISO date YYYY-MM-DD^[a-z0-9]+(?:-[a-z0-9]+)*$URL slug^#?([\dA-Fa-f]{3}|[\dA-Fa-f]{6})$Hex color