Free Regex Cheat Sheet & Pattern Builder
Visual regex reference with click-to-insert patterns, live preview, common patterns library, and code export. 100% client-side — your data stays private.
How to Use the Regex Cheat Sheet
- Click pattern buttons to insert regex tokens into the pattern builder.
- Type a test string and see matches highlighted in real time.
- Use common patterns as starting points for emails, URLs, dates, etc.
- Choose regex flags (g, i, m) from the dropdown.
- Export your pattern as JavaScript, Python, Go, or Java code.
How It Works
A regular expression is built from three core building blocks:
- Character Classes — Define what type of character to match. For example,
\dmatches any digit,\wmatches word characters (letters, digits, underscore), and[abc]matches any character in the set. - Quantifiers — Control how many times the preceding element is matched.
+means one or more,*means zero or more, and{n,m}specifies an exact range. - Anchors — Pin the match to a position rather than consuming characters.
^anchors to the start of the string,$to the end, and\bto a word boundary.
Combine these building blocks to form patterns. For example, ^\d{4}-\d{2}-\d{2}$ matches a date string like 2025-07-06 by anchoring to start/end, requiring exactly four digits, a hyphen, two digits, a hyphen, and two more digits.
Character Classes
| Pattern | Description | Example Match |
|---|---|---|
| \d | Any digit (0-9) | 3, 9 |
| \D | Any non-digit character | a, @, space |
| \w | Word character (a-z, A-Z, 0-9, _) | A, 7, _ |
| \W | Any non-word character | !, space, @ |
| \s | Whitespace (space, tab, newline) | space, \t |
| \S | Any non-whitespace character | a, 5, ! |
| [abc] | Any character in the set | a, b, c |
| [^abc] | Any character NOT in the set | d, 1, @ |
| [a-z] | Any character in the range | a, m, z |
Quantifiers
| Pattern | Description | Example Match |
|---|---|---|
| * | Zero or more of the preceding element | "" (empty), "aaa" |
| + | One or more of the preceding element | "a", "aaaa" |
| {n} | Exactly n occurrences | {3} matches "123" in "abc123xyz" |
| {n,} | At least n occurrences | {2,} matches "ab", "abcd" |
| {n,m} | Between n and m occurrences (inclusive) | {2,4} matches "ab", "abc", "abcd" |
| ? | Optional (zero or one) | "colou?r" matches "color" and "colour" |
Common Patterns
| Use Case | Regex Pattern | Example |
|---|---|---|
| Email Validation | [\w.+-]+@[\w-]+\.[\w.]+ | user@example.com |
| Phone Number | \+?[\d\s()-]{7,} | +1 (555) 123-4567 |
| URL | https?:\/\/[\w\-._~:/?#\[\]@!$&\'()*+,;=%]+ | https://example.com |
| Date Format (YYYY-MM-DD) | \d{4}-\d{2}-\d{2} | 2025-07-06 |
Why Use This Regex Tool
Regular expressions are powerful but notoriously hard to remember. This visual cheat sheet lets you browse patterns by category and insert them with a click — no memorization required.
The live preview shows you exactly what your regex matches in real time, eliminating the trial-and-error cycle. Export directly to your preferred language and paste into your code.
Frequently Asked Questions
g — global: find all matches, not just the first. i — case-insensitive. m — multiline: ^ and $ match line starts/ends, not just string start/end.
Check for escaped special characters (e.g., \. instead of .), ensure the g flag is set for multiple matches, and verify your test string matches the expected format.
Basic patterns are compatible across most languages. However, advanced features like lookaheads or named groups have syntax differences between JavaScript, Python, Go, and Java. The export feature generates language-specific code.
Use Cases
Syntax Reference
Quick regex syntax reference with click-to-insert patterns for common operations.
Quantifier Lookup
Look up regex quantifiers like *, +, ?, and {n,m} for pattern construction.
Character Classes
Find regex character classes for matching digits, words, whitespace, and custom sets.
Pattern Building
Build regex patterns from a visual reference without memorizing complex syntax.
Anchors & Groups
Learn regex anchors, groups, and lookaheads with interactive examples and export.