DevTools.run

Regex Cheatsheet

Quick reference for regular expressions

Character 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]Character set (a, b, or c)
[^abc]Negated set (not a, b, or c)
[a-z]Range

Quantifiers

*0 or more
+1 or more
?0 or 1 (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?Lazy (0 or more, minimal)
+?Lazy (1 or more, minimal)

Anchors & Boundaries

^Start of string/line
$End of string/line
\bWord boundary
\BNon-word boundary

Groups & References

(abc)Capture group
(?:abc)Non-capturing group
\1Backreference to group 1
(?<name>)Named capture group
(a|b)Alternation (a or b)

Lookahead & Lookbehind

(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind

Common Patterns

[\w.-]+@[\w.-]+\.\w+Email
https?://[\w.-]+(/\S*)?URL
\d{3}-\d{3}-\d{4}US Phone
\d{4}-\d{2}-\d{2}Date (YYYY-MM-DD)
#[0-9A-Fa-f]{6}Hex Color
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}IPv4