Regular expressions pack search rules into short symbols, and one wrong character can change every result. A regex cheat sheet keeps the common symbols in one place. This page adds a live tester, so you can check a pattern before you use it in code.
The tool suits developers, data analysts, and students who write patterns. You type a pattern, set flags, and paste sample text. Matches appear highlighted as you type, and pressing Enter runs the tester too.
Table of Contents
- What the Regex Cheat Sheet Does
- How to Use the Regex Cheat Sheet
- How the Live Tester Works
- Worked Example
- How to Read the Results
- Common Mistakes and Useful Tips
- Limitations and Assumptions
- FAQs About the Regex Cheat Sheet
What the Regex Cheat Sheet Does
The page has two parts: a live sandbox and three reference tables of common syntax. The sandbox uses JavaScript regex rules, and the page header says so.
- Live Regex Sandbox: a Regex Pattern box, a Flags box, and a Test Text box.
- Matches Highlighted: a result panel that wraps each match in a yellow highlight.
- Matched count line: the number of highlighted matches the tester found.
- Character Classes table: the dot, digit, word, whitespace, and set syntax.
- Anchors & Quantifiers table: start and end markers, word boundaries, and repeat counts.
- Groups & Flags table: capturing and non-capturing groups, alternation, and the seven JavaScript flags.
For more tools like this, browse the developer tools hub.
How to Use the Regex Cheat Sheet
- Type a pattern in the Regex Pattern box. The sample is a loose email address pattern.
- Enter letters in the Flags box. The sample uses gi, where i means case insensitive.
- Type or paste sample text in the Test Text box. The sample is one short contact line.
- Read the Matches Highlighted panel. Each match appears inside a yellow highlight.
- Check the Matched count line under the highlighted text.
- Use the reference tables to look up symbols as you edit.
How the Live Tester Works
The tester builds a JavaScript regular expression from your pattern and flags. It then scans the test text, wraps each match in a highlight, and counts the matches.
Pattern+Flags→Find Every Match→Highlight and Count
The match runs in a Web Worker, which is a background script inside your browser. The worker sends back the position of each match. The page then builds each highlight from those positions.
- Pattern: the text in the Regex Pattern box.
- Flags: the letters in the Flags box.
- Test text: the text in the Test Text box, scanned for matches.
A blank box shows a prompt that names the empty field. If the browser rejects the pattern or flags, the tool shows its error message.
Worked Example
Priya tests two patterns on sample text. The first is the default email pattern with the gi flags. The second matches phone style numbers with the g flag.
| Pattern and Flags | Test Text | Result |
| [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} with gi | Contact info: john.doe@example.com or support@company.org for assistance. | Matched 2 occurrence(s): john.doe@example.com and support@company.org |
| \d{3}-\d{4} with g | Call 555-1234 or 555-9876 today. | Matched 2 occurrence(s): 555-1234 and 555-9876 |
| \d{3}-\d{4} with g | No numbers here. | Matched 0 occurrence(s), and the text appears unchanged |
Priya then removed the g flag from the email pattern and kept the i flag. The count stayed at 2, and both addresses received a highlight. The tester still found every match without the g flag.
How to Read the Results
Matches Highlighted shows the full test text. Each match sits inside a yellow highlight, and all other text stays plain. Line breaks in the test text stay as line breaks.
Matched N occurrence(s) reports the number of highlighted matches. Compare this number with the text to check your hit count.
Zero-length match(es) found, not highlighted. This line appears only when a pattern matches empty text. The count is shown, but no highlight is drawn for those matches.
Matching... appears while a run is pending. The result replaces it when the run finishes.
Stopped after 2 seconds. A run that takes too long ends with this message. Simplify the pattern or shorten the text, then try again.
Enter a regex pattern. and Enter some test text. name the empty box. Invalid Regex: means the browser rejected the pattern or flags, and the error follows.
Common Mistakes and Useful Tips
Zero-width patterns can mislead you. A pattern such as x* or a word boundary matches empty text. The tester counts those empty matches on a separate line, and it never highlights them. For example, x* on abc shows no highlights and reports 4 zero-length matches.
Nested repeats can slow a pattern down. A pattern such as (a+)+$ can run for a long time on long text with no match. Shorten the sample or rewrite the pattern with fewer nested repeats.
To match a special character as plain text, escape it first with the Regex Escape Tool. For a broader pattern search, the Regex Tester is a related option.
Limitations and Assumptions
- The tester follows JavaScript regular expression rules only. It does not run PCRE, Python, or Java rules.
- The tester never stops at the first match, so it does not show how a flagless JavaScript search behaves.
- The time limit is fixed. A valid but slow pattern on a slow device can stop early.
- If the browser blocks workers, the tester runs the match on the page with no time limit.
- The tester does not show match positions for the d flag. It shows highlights and counts only.
- The tester does not test replacement strings. For that job, see the Regex Replace Tester. A starting pattern can also come from the Regex Generator.
FAQs About the Regex Cheat Sheet
What Does the g Flag Do in the Tester?
The tester adds g on its own, so it always highlights and counts every match. In your own code, g still decides whether every match is found.
Why Does My Pattern Show Invalid Regex?
The browser rejected the pattern or the flags. Check for unclosed brackets, unclosed parentheses, or unknown flag letters. The message after the colon names the problem.
Does This Tester Work for Python or PHP Regex?
It uses JavaScript rules, so simple patterns often work across languages. Python named groups fail here with an invalid group error. Use (?<name>...) for JavaScript named groups.
Why Do My Line Anchors Not Match Each Line?
The caret and dollar sign match the start and end of the whole text by default. Add the m flag to match at the start and end of each line.
Is My Text Saved or Sent to a Server?
No, the page code runs in your browser, makes no network requests, and stores nothing. The matching helper, a Web Worker, also lives only in memory.
Does the Cheat Sheet List Every Regex Symbol?
No. It covers common character classes, anchors, quantifiers, groups, and seven flags. Lookarounds and other advanced syntax are not in the tables, so check your language reference for those.
This calculator gives general estimates only and is not professional advice. Reviewed for general accuracy by Prof. Dr. Khalil Mudassar, PhD.