πŸ“‹ Regex Cheat Sheet

Interactive regex reference with live pattern tester

Zero Dependencies Β· Works Offline

πŸ§ͺ Live Regex Tester

πŸ”€ Character Classes

.Any character (except newline)
\\dDigit [0-9]
\\DNot a digit [^0-9]
\\wWord character [a-zA-Z0-9_]
\\WNot a word character
\\sWhitespace (space, tab, newline)
\\SNot whitespace
[abc]Any of a, b, or c
[^abc]Not a, b, or c
[a-z]Character range a to z

πŸ”’ Quantifiers

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

πŸ“ Anchors & Boundaries

^Start of string/line
$End of string/line
\\bWord boundary
\\BNot a word boundary

πŸ“¦ Groups & References

(abc)Capturing group
(?:abc)Non-capturing group
(?<name>abc)Named capturing group
\\1Backreference to group 1
\\k<name>Backreference to named group
|Alternation (OR)

πŸ‘οΈ Lookaround

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

⚑ Special Characters

\\Escape special character
\\nNewline
\\tTab
\\rCarriage return
\\xHHHex character
\\uHHHHUnicode character

🚩 Flags

gGlobal β€” find all matches
iCase-insensitive
mMultiline β€” ^ and $ match line boundaries
sDotall β€” . matches newline
uUnicode β€” enable Unicode support
ySticky β€” match at current position

What Is the Regex Cheat Sheet?

The Regex Cheat Sheet is a free online interactive reference for regular expressions. It provides a comprehensive quick-reference table for regex metacharacters, quantifiers, anchors, groups, lookarounds, and flags, combined with a live pattern tester. Click any pattern in the reference to insert it into the tester. All processing runs locally in your browser.

Core Features

Common Regex Patterns

Email: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/

URL: /^https?:\\/\\/(www\\.)?[a-zA-Z0-9-]+\\.[a-zA-Z]{2,}(\\/\\S*)?$/

Phone (US): /^\\(?\\d{3}\\)?[-.\\s]?\\d{3}[-.\\s]?\\d{4}$/

IP Address: /^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/

Regex Best Practices

Use non-capturing groups (?:...) when you don't need to reference the group. Prefer character classes over alternation for single characters ([abc] vs a|b|c). Use anchors (^ and $) to prevent partial matches. Be careful with greedy quantifiers on large inputs β€” they can cause catastrophic backtracking. Test your patterns with edge cases including empty strings and special characters.

❓ FAQ

What is a regular expression?

A sequence of characters defining a search pattern for string matching, validation, and text parsing.

Greedy vs lazy quantifiers?

Greedy (*, +) match as much as possible. Lazy (*?, +?) match as little as possible.

What are lookaheads/lookbehinds?

Zero-width assertions that check what comes after/before without consuming characters.

Is my data uploaded?

No. All regex testing happens locally in your browser.

Which regex flavor?

JavaScript ECMAScript RegExp. Most patterns are compatible with PCRE, Python, and Java.

How to escape special characters?

Use backslash: \\. matches a literal dot, \\\\ matches a literal backslash.