Regex Tester
Build and debug regular expressions with instant feedback
What Is a Regular Expression?
A regular expression, or regex, is a small pattern language for
describing text. \d{3} means "three digits",
^[A-Z] means "starts with a capital letter", and
colou?r matches both "color" and "colour". Regexes are
used to validate input, search logs, extract data and rewrite text
in almost every programming language and editor.
Key Features
- Live highlighting: Matches are marked in your text as you type
- Groups: Every match lists its numbered groups ($1, $2) and named groups ($<name>)
- Replace preview: See the result of a replacement, including group references
- All JavaScript flags: g, i, m, s, u and y, each with a tooltip
- Runaway protection: Patterns that take too long are stopped instead of freezing your tab
- Quick reference: The most used syntax, right below the tester
- Remembers your work: Pattern, flags and text are kept when you reload
How to Test a Regex
Step 1: Enter the Pattern
Type your pattern between the slashes, without the slashes themselves. Click "Sample" to load an email-matching example with named groups.
Step 2: Choose Flags
The g flag is on by default so you see every match. Add
i to ignore case, m to make ^
and $ work per line, or s to let
. match line breaks. The flags you pick appear after the
closing slash.
Step 3: Add Test Text
Paste the text you want to search. Include examples that should match and examples that shouldn't, so you catch both missed matches and false positives.
Step 4: Read the Results
The status line gives the number of matches and groups. The highlighted view shows where each match sits, and the Matches list shows its position and every group value. A group that didn't take part in the match is shown as "(no match)".
Step 5: Try a Replacement
Type a replacement to preview the rewritten text. Use
$1 for the first group, $<name> for a
named group and $& for the whole match. Without the
g flag, only the first match is replaced, exactly as in
JavaScript's String.replace.
Regex Flags Explained
- g (global): Find all matches, not just the first
- i (ignore case):
aalso matchesA - m (multiline):
^and$match at the start and end of each line - s (dotAll):
.also matches line breaks - u (unicode): Treats emoji and other astral characters as one character, and enables
\p{L}style classes - y (sticky): Only matches at the exact current position
Useful Patterns
- Whole word:
\bword\b - Digits only:
^\d+$ - ISO date:
\d{4}-\d{2}-\d{2} - Hex colour:
#(?:[0-9a-fA-F]{3}){1,2}\b - Trailing whitespace:
[ \t]+$with the m flag - Duplicate words:
\b(\w+)\s+\1\b
Avoiding Catastrophic Backtracking
Some patterns, such as (a+)+$, can take exponentially
longer as the input grows, because the engine tries every way to
split the text between the nested quantifiers before giving up. In
production this can hang a server. The tester runs your pattern in
the background and stops it after 1.5 seconds, so you find these
problems safely. To fix one, remove nested quantifiers, make
alternatives mutually exclusive, and use specific character classes
instead of .*.
Tips
- Build patterns step by step, checking the matches after each change
- Use named groups;
$<year>is easier to read than$3 - Prefer lazy quantifiers like
.+?when matching between delimiters - Anchor validation patterns with
^and$, or partial input will pass
Privacy
Your pattern and text are processed in your browser and saved only in its local storage. Nothing is uploaded.
Conclusion
Live highlighting, group details and replace previews make regular expressions far easier to get right. Try it at tools.typinks.com/regex-tester.