Regex Cheatsheet, The Complete Pattern Reference
Stop searching scattered documentation every time you forget a quantifier or flag.
3 matches
1 12 123 12345
| # | Index | Match |
|---|---|---|
| 1 | 2–4 | 12 |
| 2 | 5–8 | 123 |
| 3 | 9–13 | 1234 |
Regex cheatsheet
Anchors
| ^ | Start of the text (of each line with m) | |
| $ | End of the text (of each line with m) | |
| \b | Word boundary | |
| \B | Not a word boundary |
Character classes
| . | Any character except a line break (any with s) | |
| \d \D | Digit 0-9 / not a digit | |
| \w \W | Letter, digit or _ (ASCII) / anything else | |
| \s \S | Whitespace (space, tab, line break) / not whitespace | |
| [abc] | One of the listed characters | |
| [^abc] | Any character not listed | |
| [a-z] | A range of characters | |
| \p{L} | Unicode property, here any letter (needs u) |
Quantifiers
| * | 0 or more | |
| + | 1 or more | |
| ? | 0 or 1 (optional) | |
| {n} {n,} {n,m} | Exactly n / n or more / between n and m | |
| *? +? ?? | Lazy: as few as possible |
Groups and references
| (…) | Capturing group ($1, $2 …) | |
| (?<name>…) | Named group ($<name>) | |
| (?:…) | Group without capturing | |
| a|b | Either side | |
| \1 \k<name> | Same text as group 1 / as a named group |
Lookaround
| (?=…) | Followed by (positive lookahead) | |
| (?!…) | Not followed by (negative lookahead) | |
| (?<=…) | Preceded by (positive lookbehind) | |
| (?<!…) | Not preceded by (negative lookbehind) |
Escapes
| \. \* \( \\ | A literal special character | |
| \n \t \r | Line break / tab / carriage return | |
| \uFFFF \u{1F600} | A character by its code (the {…} form needs u) |
Runs on your browser's JavaScript regex engine. Nothing is uploaded.
Full coverage of anchors, classes, quantifiers, and groups
Lookahead and lookbehind syntax with examples
Flags g, i, m, s, u and y explained next to their checkboxes
Load any example into the live tester with one click
- Cost
- Free tier
- Sign-up
- Not required
- Processing
- Tool-specific
- Privacy
- Clearly disclosed
Add this Regex Tester to your website
Drop the Regex Tester into a blog post, product docs, intranet, or school portal with one iframe. Processing, privacy, and usage limits are the same as on the full tool page.
- One copy-ready line of HTML
- Responsive — adapts to any container width
- No API credentials are placed in the snippet
Embed code
<iframe
src="https://www.fixtools.io/developer/regex-tester?embed=1"
width="100%"
height="780"
frameborder="0"
style="border:0;border-radius:16px;max-width:900px;"
title="Regex Tester by FixTools"
loading="lazy"
allow="clipboard-write"
></iframe>Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.
Why a Regex Cheatsheet Belongs in Every Developer Workflow
Regular expression syntax has remained largely stable for decades, but its density means that even experienced developers frequently forget the exact token for a behaviour they have not used recently. Is it (?<=...) or (?=...) for a lookbehind? Does {3,} mean three or more, or exactly three? A cheatsheet eliminates those questions without requiring a full documentation read. It is the difference between a five-second lookup and a two-minute context switch to a documentation site that requires further navigation to the right section. For teams onboarding developers who are new to regex, a concise cheatsheet also serves as a structured introduction: it maps the abstract concept to the concrete syntax and a minimal example in a single line, which is faster to absorb than reading a tutorial that starts from theory.
The core taxonomy of regex tokens breaks into six groups. Anchors (^, $, \b, \B) match positions rather than characters, asserting where in the string a match must occur without consuming any input. Character classes ([a-z], \d, \w, \s and their uppercase negations) describe sets of characters that can occupy a position. Quantifiers (*, +, ?, {n}, {n,m}) specify how many times the preceding token must occur. Groups ((...) and (?:...)) scope quantifiers and optionally capture substrings. Lookarounds ((?=...), (?!...), (?<=...), (?<!...)) assert surrounding context without consuming characters. Flags (g, i, m, s, u, y) modify how the engine traverses the input at a global level. Understanding which group a token belongs to resolves most syntax confusion instantly and provides the right mental model for combining tokens correctly.
For practical sessions, the most productive approach is to keep the cheatsheet open in an adjacent browser tab during any regex-heavy work. Write the pattern in the tester, look up any uncertain token in the cheatsheet, paste the cheatsheet example into the tester to confirm your understanding, then return to building your pattern. This three-tab workflow covering cheatsheet, tester, and your codebase handles the full cycle from syntax lookup to verified pattern without requiring you to leave the browser or break the development flow for a longer documentation excursion.
Cross-flavour awareness matters because regex syntax varies more across engines than newcomers expect. The shorthand classes \d and \w mean ASCII-only digits and word characters in JavaScript even with the u flag (\s already matches Unicode whitespace), but mean Unicode-aware sets in .NET and in Python under re.UNICODE which is the default in Python 3. Named-group syntax is (?<name>...) in JavaScript, .NET, and PCRE, but (?P<name>...) in Python's re module. Possessive quantifiers like a++ and atomic groups (?>...) work in Java and PCRE but throw syntax errors in JavaScript. Knowing these differences means you do not waste time chasing a pattern that looks correct but was copied from a tutorial written for a different engine. When in doubt, write a tiny test case in the target language's real environment before trusting a pattern.
How to use this tool
Open the Regex Tester alongside this cheatsheet. Copy any pattern from the reference, paste it into the tester, and test it against your real data immediately.
How It Works
Step-by-step guide to regex cheatsheet, the complete pattern reference:
- 1
Identify the token category
Decide whether the behaviour you need falls under anchors (position matching), character classes (set membership), quantifiers (repetition counts), groups (scoping and capturing), lookarounds (context assertions), or flags (engine-level settings, explained next to the flag checkboxes). This categorisation tells you which section of the cheatsheet to consult first and prevents you from searching the wrong area.
- 2
Find the token in the cheatsheet
Locate the relevant section of the cheatsheet and identify the specific token or syntax form you need. Read the brief explanation alongside the token to confirm it describes the behaviour you want. Copy the example pattern if one is provided: using the example as a starting point is faster than writing the syntax from memory.
- 3
Open the Regex Tester
Paste the copied example pattern into the pattern field of the live tester. This immediately confirms that the syntax is valid and shows you what the example matches. Adapt the example to your specific use case by modifying the character classes, quantifiers, or anchors in the pattern field.
- 4
Paste your test data
Enter representative strings from your project into the test string area to verify that the pattern based on the cheatsheet example behaves as the documentation describes. If it does not, return to the cheatsheet to check whether a flag or additional syntax modification is required for your specific context.
Real-world examples
Common situations where this approach makes a real difference:
Confirming the syntax for a word boundary anchor
A developer wants to match the word "cat" only as a standalone word, not as a substring inside "concatenate" or "scatter". Looking up \b in the cheatsheet confirms it matches a zero-width word boundary between a word character and a non-word character. The pattern \bcat\b is pasted into the tester against "I have a cat and a concatenation problem". Only the standalone "cat" is highlighted, with no match inside "concatenation", confirming the anchor behaves as documented and the pattern is ready for the search feature.
Looking up how to match one or more digits non-greedily
A developer processing HTML attribute values needs to match the shortest sequence of digits between quotation marks, not the longest span across multiple attributes. The cheatsheet shows that \d+? is the lazy variant of \d+. Testing the string height="100" width="200" with the pattern "\d+?" in the tester confirms each digit group is captured individually as 100 and 200 (the greedy "\d+" gives the same two matches here, because \d cannot cross a quotation mark).
Checking lookahead syntax for a password strength rule
A security engineer needs a pattern that only matches if a string contains at least one uppercase letter and at least one digit, without consuming characters or prescribing their positions. The cheatsheet shows (?=.*[A-Z]) and (?=.*\d) as positive lookahead forms. Combining them into ^(?=.*[A-Z])(?=.*\d).{8,}$ and testing against sample passwords of varying strength in the tester confirms that the rule correctly enforces both requirements simultaneously without restricting where in the string the uppercase letter or digit appears.
Teaching a junior developer the difference between * and +
A tech lead uses the cheatsheet during a code review to explain why \d* matched an empty string at a position where \d+ was clearly the intended choice. The cheatsheet entry shows that * means zero or more occurrences while + means one or more and requires at least one match. Testing both patterns against an empty string in the tester makes the difference immediately visual: \d* highlights the empty position while \d+ produces no match. The demonstration takes under 30 seconds and cements the concept far more effectively than a verbal explanation.
When to use this guide
Use this page when you need a quick lookup for regex syntax, want to confirm the exact token for a behaviour, or are introducing a colleague to regular expressions for the first time.
Pro tips
Get better results with these expert suggestions:
Group cheatsheet tokens by what they match versus what they assert
Tokens that consume characters (character classes, literals, quantified groups) behave fundamentally differently from tokens that assert position (anchors, lookarounds). Keeping this distinction in mind when reading a cheatsheet prevents a common mistake: attempting to quantify an anchor such as writing ^+ or \b?, which JavaScript rejects as a syntax error because anchors match zero-width positions and do not consume input that a quantifier could count.
Learn the six flags before the advanced token types
The g, i, m, s, u, and y flags change how the entire engine processes input, not just individual tokens. Misunderstanding flag behaviour accounts for a disproportionately large share of "my pattern works in the tester but not in my code" issues. Mastering what each flag does and when each is appropriate resolves an entire category of subtle bugs before they are written, making flag knowledge one of the highest-return topics in the cheatsheet.
Use the cheatsheet to review unfamiliar patterns from colleagues
When reviewing code containing a regex pattern you do not immediately recognise, cross-reference each unfamiliar token against the cheatsheet before asking a question. This practice builds pattern-reading fluency over time, usually resolves the uncertainty in under a minute, and avoids interrupting the original author for explanations that the cheatsheet can provide faster.
Bookmark the cheatsheet alongside the live tester
Keep both the cheatsheet page and the regex tester open in adjacent browser tabs during any session where you are writing or reviewing patterns. The lookup-and-verify cycle takes under 30 seconds per uncertain token and is far faster than navigating a search engine, reading a tutorial page, and returning to your work. The proximity of the two tools in adjacent tabs is what makes the habit practical.
Frequently asked questions
Related guides
More use-case guides for the same tool:
Ready to get started?
Open Regex Tester to review its free limits and processing method.
Open Regex Tester →Free tier · No account needed · Transparent limits