Regex Cheatsheet for Developers

regexreferencecheatsheet

Regular Expression Quick Reference

Regular expressions (regex) are patterns used to match character combinations in strings. This cheatsheet covers the most common regex syntax you’ll need as a developer.

Test any pattern with our Regex Tester.

Character Classes

PatternDescriptionExample
.Any character (except newline)a.c matches “abc”, “a1c”
\dAny digit (0-9)\d{3} matches “123”
\DAny non-digit\D+ matches “abc”
\wWord character (a-z, A-Z, 0-9, _)\w+ matches “hello_123”
\WNon-word character\W matches “@”, " "
\sWhitespace (space, tab, newline)\s+ matches " "
\SNon-whitespace\S+ matches “hello”
[abc]Character set (a, b, or c)[aeiou] matches vowels
[^abc]Negated set (not a, b, or c)[^0-9] matches non-digits
[a-z]Character range[A-Za-z] matches letters

Quantifiers

PatternDescriptionExample
*0 or more\d* matches “”, “123”
+1 or more\d+ matches “1”, “123”
?0 or 1 (optional)colou?r matches “color”, “colour”
{n}Exactly n times\d{4} matches “2024”
{n,}n or more times\d{2,} matches “12”, “123”
{n,m}Between n and m times\d{1,3} matches “1”, “12”, “123”
*?Lazy (minimal match)".+?" matches "a" in "a" "b"

Anchors

PatternDescription
^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary
\BNon-word boundary

Groups and Alternation

PatternDescriptionExample
(abc)Capturing group(ha)+ matches “haha”
(?:abc)Non-capturing group(?:ha)+ same but no capture
\1Backreference(a)\1 matches “aa”
a|bAlternation (or)cat|dog matches “cat” or “dog”

Lookahead and Lookbehind

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

Common Patterns

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

JavaScript Regex Flags

FlagDescription
gGlobal — find all matches
iCase-insensitive
mMultiline — ^ and $ match line boundaries
sDotAll — . matches newlines
uUnicode support

Try It Live

Test all these patterns in our Regex Tester — with real-time match highlighting and group extraction.