Regex Cheatsheet
Complete interactive regular expression reference with live testing. Character classes, quantifiers, groups, lookaheads, and common patterns.
Live Regex Tester
Character Classes
.Any character except newline
a.c → "abc", "a1c", "a-c"
\dAny digit (0-9)
\d{3} → "123", "456"
\DAny non-digit
\D+ → "abc", "hello"
\wWord character (a-z, A-Z, 0-9, _)
\w+ → "hello_42"
\WNon-word character
\W → "!", "@", " "
\sWhitespace (space, tab, newline)
a\sb → "a b", "a\tb"
\SNon-whitespace
\S+ → "hello", "42"
[abc]Any of a, b, or c
[aeiou] → "a", "e", "i"
[^abc]Not a, b, or c
[^0-9] → "a", "!"
[a-z]Range: a to z
[A-Za-z] → "a", "Z"
Quantifiers
*Zero or more
ab*c → "ac", "abc", "abbc"
+One or more
ab+c → "abc", "abbc" (not "ac")
?Zero or one
colou?r → "color", "colour"
{n}Exactly n times
\d{4} → "2024", "1234"
{n,}n or more times
\d{2,} → "12", "123", "1234"
{n,m}Between n and m times
\d{2,4} → "12", "123", "1234"
*?Zero or more (lazy)
<.*?> → "<b>" (not "<b>text</b>")
+?One or more (lazy)
\w+? → First character only
Anchors & Boundaries
^Start of string/line
^Hello → "Hello world" (start)
$End of string/line
world$ → "Hello world" (end)
\bWord boundary
\bcat\b → "cat" (not "catch")
\BNon-word boundary
\Bcat\B → "concatenate" (inner)
Groups & References
(abc)Capturing group
(\d{3})-(\d{4}) → "123-4567"
(?:abc)Non-capturing group
(?:ab)+ → "abab"
(?<name>)Named group
(?<year>\d{4}) → "2024"
\1Back-reference to group 1
(\w)\1 → "aa", "bb"
(a|b)Alternation (or)
(cat|dog) → "cat" or "dog"
Lookahead & Lookbehind
(?=abc)Positive lookahead
\d(?=px) → "5" in "5px"
(?!abc)Negative lookahead
\d(?!px) → "5" in "5em"
(?<=abc)Positive lookbehind
(?<=\$)\d+ → "50" in "$50"
(?<!abc)Negative lookbehind
(?<!\$)\d+ → "50" in "50"
Flags
gGlobal - match all occurrences
/cat/g → All "cat" matches
iCase-insensitive
/hello/i → "Hello", "HELLO"
mMultiline - ^ and $ match per line
/^start/m → Start of each line
sDotall - . matches newlines
/a.b/s → "a\nb"
Common Patterns
EmailBasic email validation
[\w.-]+@[\w.-]+\.\w{2,} → "user@site.com"
URLBasic URL matching
https?://[\w./%-]+ → "https://site.com/path"
IP AddressIPv4 address
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} → "192.168.1.1"
PhoneUS phone number
\d{3}[-.\s]?\d{3}[-.\s]?\d{4} → "555-123-4567"
Hex ColorCSS hex color
#[0-9a-fA-F]{3,6} → "#fff", "#FF0000"
DateYYYY-MM-DD format
\d{4}-\d{2}-\d{2} → "2024-01-15"
Frequently Asked Questions
Related Tools
Regex Tester
Test and debug regular expressions in real-time. Matches highlighted, capture groups, replacements.
Regex Builder
Build regular expressions visually with real-time matching, a cheat sheet, and common pattern library. No more guessing at regex syntax.
JSON Formatter
Format, validate, and minify JSON data with syntax highlighting.
Base64 Encoder / Decoder
Encode text to Base64 or decode Base64 strings back to plain text.
CSV to JSON Converter
Convert CSV data to JSON arrays and JSON arrays back to CSV. Custom delimiters supported.
Text Diff Checker
Compare two texts and see additions, removals, and unchanged lines highlighted side by side.