Interactive Regex Cheatsheet
Searchable regex token reference with a live sandbox for testing patterns, match highlighting, capture groups, and substitution.
How to Use
This interactive regex cheatsheet combines a comprehensive token reference with a live testing sandbox. Browse regex syntax by category, search for specific tokens, and test patterns in real time with instant match highlighting and capture group extraction.
- Browse the reference: The left panel organizes 45+ regex tokens into eight categories: Character Classes, Anchors, Quantifiers, Groups, Alternation, Assertions, Escapes, and Flags. Expand or collapse any category to focus on what you need.
- Search tokens: Type a keyword (e.g., "lookahead", "digit", or "\d") in the search bar to instantly filter the reference. Results update as you type.
- Try It in the sandbox: Hover over any token entry and click "Try It" to load its example pattern and test string into the live sandbox. The pattern executes immediately and shows highlighted matches.
- Test your own patterns: Enter any regex pattern in the sandbox input field. Type or paste your test string below. Matches highlight in real time with color-coded spans. Each match shows its index position and any capture groups.
- Toggle flags: Click the flag buttons (g, i, m, s, u, y) to enable or disable regex flags. Active flags appear highlighted. The global flag (g) is enabled by default to show all matches.
- Use Replace mode: Switch to the Replace tab to test substitution patterns. Enter a replacement string using $1, $2 for back-references or $$<name> for named groups. The result updates live.
- Try common patterns: Click any of the pre-built patterns (Email, URL, IPv4, Hex Color, Phone, Date) in the Quick Patterns section to instantly load and test them.
About This Tool
Regular Expression Syntax Overview
Regular expressions (regex) are patterns used to match character combinations in strings. They are supported in virtually every programming language, text editor, and command-line tool. A regex pattern consists of literal characters and metacharacters that define match rules. For example, \d3-\d4 matches a phone number like "555-1234" by specifying exactly three digits, a literal hyphen, and four more digits.
Character Classes and Shorthand Notation
Character classes define sets of characters to match. Square brackets [abc] match any single character from the set. Ranges like [a-z] match any lowercase letter. Negated sets [^0-9] match anything not in the set. JavaScript provides shorthand classes: \d for digits (equivalent to [0-9]), \w for word characters ([a-zA-Z0-9_]), and \s for whitespace. Their uppercase counterparts \D, \W, \S match the inverse.
Quantifiers: Greedy vs Lazy Matching
Quantifiers control how many times the preceding element must match. The asterisk * matches zero or more times, + matches one or more, and ? matches zero or one. Curly braces specify exact counts: {3} for exactly three, {2,5} for two to five. By default, quantifiers are greedy, consuming as many characters as possible. Adding ? after a quantifier makes it lazy (non-greedy), matching the minimum number of characters. This distinction is critical when parsing structured formats like HTML tags, where greedy matching captures too much text.
Groups, Captures, and Back-References
Parentheses () create capturing groups that save matched text for later reference. Back-references like \1 match the same text captured by the first group. Named groups (?<name>...) improve readability by assigning descriptive names to captures. Non-capturing groups (?:...) group tokens without saving the match, which is useful when you need grouping for quantifiers but do not need to extract the matched text. In the Find and Replace tool, capture groups enable powerful text transformations using $1, $2 substitution patterns.
Lookahead and Lookbehind Assertions
Zero-width assertions check for patterns without consuming characters. Positive lookahead (?=...) asserts that what follows matches a pattern. Negative lookahead (?!...) asserts the opposite. Lookbehind assertions (?<=...) and (?<!...) check what precedes the current position. These are invaluable for extracting values that appear in specific contexts, such as matching a number only when preceded by a dollar sign, without including the dollar sign in the match result.
Why Use This Tool
Interactive Learning, Not Just Reference
Static cheatsheets list tokens but do not let you experiment. This tool combines a searchable reference with a live sandbox where every token has a "Try It" button that loads a working example. You see the pattern match immediately, including capture group values and match indices. This makes it significantly faster to learn regex by doing rather than just reading syntax tables.
Built for Developers Who Work Across Languages
Regex syntax is nearly universal across JavaScript, Python, Java, Go, Ruby, and PHP. The core tokens, quantifiers, character classes, and assertions documented here apply in all these languages. Whether you are writing validation logic in a JSON Formatter, building patterns for a Code Diff tool, or extracting data with a Text Extractor, the regex fundamentals remain the same. Everything runs 100% client-side in your browser — your patterns and test data never leave your device.
Protection Against Catastrophic Backtracking
Poorly written regex patterns can cause catastrophic backtracking, where the engine explores exponentially many paths before failing. This sandbox includes a 2-second timeout guard that terminates runaway patterns and warns you about potential ReDoS issues. This safety net lets you experiment freely without freezing your browser tab, making it ideal for testing untrusted or complex patterns before deploying them in production code.