A regex cheatsheet (regular expression reference) gives you instant access to the syntax patterns you need without digging through documentation. Use the sections below to look up character classes, quantifiers, anchors, groups, and lookaheads — then test your pattern live in the interactive tester at the top.
Live Regex Tester
Common Presets
Character Classes
Quantifiers
Anchors
Groups & Alternation
Lookahead & Lookbehind
Flags
Escape Sequences & Special Characters
How to Use the Regex Cheatsheet
Regular expressions (regex) are compact pattern strings that describe how to match, find, or replace text. They are supported in virtually every programming language and text editor. This regex cheatsheet covers the universal syntax that works in JavaScript, Python, PHP, Ruby, Java, and most other environments.
Step 1: Find the syntax you need
Each collapsible section covers a different category of regex syntax. Click any section header to expand or collapse it. The table columns show the pattern, what it does, and a concrete example of what it matches. All sections start open so you can scan everything at a glance.
Step 2: Click a pattern to copy it
Every pattern in the cheatsheet is a clickable button. Clicking one copies the pattern to your clipboard instantly — no text selection required. A toast notification confirms the copy. You can also click any pattern to auto-load it into the live tester above so you can experiment with it immediately.
Step 3: Test your pattern live
The live tester at the top of the page lets you enter any regex pattern and a test string. Matches are highlighted in the output panel in real time. Toggle the g, i, m, s, and u flags using the checkboxes. If your pattern is invalid, an error message is shown below the input.
Step 4: Use the common presets
The presets section provides ready-made regex patterns for the most common use cases: email addresses, URLs, phone numbers, dates, IP addresses, hex color codes, and more. Click any preset to instantly load the pattern into the tester with a sample string so you can see how it works before adapting it to your needs.
Key regex concepts to remember
Greedy vs. lazy: By default, quantifiers like * and + are greedy — they match as much as possible. Add a ? after them (*?, +?) to make them lazy — matching as little as possible.
Anchors are zero-width: ^ and $ don't match characters — they match positions. \b matches the boundary between a word character and a non-word character.
Escape metacharacters: The characters . * + ? ^ $ { } [ ] | ( ) \ have special meaning in regex. To match them literally, escape with a backslash: \. matches a literal dot.
Lookaheads are zero-width too: (?=...) and (?!...) assert what follows the current position without consuming characters, so they don't appear in the match result.
Frequently Asked Questions
Is this regex cheatsheet free to use?
Yes, the regex cheatsheet is 100% free with no signup, no account, and no limits. The live test area also runs entirely in your browser.
Is my test data private?
Absolutely. The live test area runs entirely in your browser using JavaScript. Your regex patterns and test strings are never sent to any server and never stored.
What regex flavor does the live tester use?
The live tester uses JavaScript's built-in RegExp engine. JavaScript regex is similar to PCRE but has some differences — notably, it uses named groups with the (?<name>...) syntax and supports the global, case-insensitive, multiline, dotAll, sticky, and unicode flags.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (like * and +) match as much as possible while still allowing the overall pattern to succeed. Lazy quantifiers (like *? and +?) match as little as possible. For example, a.*b on 'aXbYb' greedy matches 'aXbYb', while a.*?b matches only 'aXb'.
What is the difference between a capturing group and a non-capturing group?
A capturing group (...) captures the matched text so you can reference it later via $1, $2, etc. or group[1] in code. A non-capturing group (?:...) groups the pattern for quantifiers or alternation without creating a back-reference, which is slightly faster and cleaner when you don't need the capture.
What is the difference between lookahead and lookbehind?
Lookahead (?=...) and negative lookahead (?!...) assert what follows the current position without consuming characters. Lookbehind (?<=...) and negative lookbehind (?<!...) assert what precedes the current position. Both are zero-width — they don't include the matched text in the result.
How do I match a literal dot, star, or parenthesis in regex?
Escape special characters with a backslash. For example, \. matches a literal dot, \* matches a literal asterisk, \( and \) match literal parentheses, and \\ matches a literal backslash. Any metacharacter (.^$*+?{}[]|()\) must be escaped to be treated as a literal character.
Can I use this cheatsheet for Python or other languages?
Most of the syntax shown here applies to PCRE-compatible engines used in Python (re module), PHP, Ruby, Java, and .NET. The main differences are in flag syntax and named group syntax. Python uses (?P<name>...) for named groups, while JavaScript uses (?<name>...).