How to use the Regex Tester
- 1Type a pattern and choose flags (g, i, m, s, u, y).
- 2Paste test text. Matches are highlighted instantly.
- 3Check the groups table for capture group values.
- 4Switch on replace mode to preview a replacement string with $1 and named groups.
What is a regex tester?
A regex tester lets you try a regular expression (regex) against sample text and see what it matches before you use it in code. This tester highlights every match as you type, lists capture groups in a table, supports all JavaScript flags, has a replace mode with $1 and named groups, and includes a cheat sheet and a library of common patterns.
A regular expression is a small pattern language for finding text. For example, \d{4}-\d{2}-\d{2} finds dates like 2026-12-01.
How does the regex tester work?
It uses your browser's own JavaScript regular expression engine, the same one that runs your code in Chrome, Firefox, Safari or Node.js. The syntax follows the ECMAScript standard, documented clearly on MDN's regular expressions guide.
When you type, the tool:
- Builds a
RegExpfrom your pattern and flags. If that fails, it shows the browser's error message. - Runs
matchAll(or a singlematchwithout thegflag) on your text. - Highlights each match and fills the groups table with each match's position and captured groups.
It shows up to 1,000 matches so a pattern that matches every character can't freeze the page.
What do the flags do?
| Flag | Name | Effect |
|---|---|---|
g | global | Find all matches, not just the first |
i | ignore case | a matches A |
m | multiline | ^ and $ match at the start and end of each line |
s | dotAll | . also matches newline characters |
u | unicode | Treats emoji and other astral characters as one character; enables \p{…} classes |
y | sticky | Matches only at the current position |
Use u whenever your text may contain Urdu, Arabic or emoji and you use classes like \p{L} (any letter in any language).
Worked example
Pattern: \b(\w+)@(\w+)\.com\b with flag g
Text: Contact ali@example.com or sara@test.com for help.
Results: 2 matches.
| # | Match | Index | Group 1 | Group 2 |
|---|---|---|---|---|
| 1 | ali@example.com | 8 | ali | example |
| 2 | sara@test.com | 27 | sara | test |
Turn on replace mode with $1 at $2 and the result is Contact ali at example or sara at test for help. With named groups, (?<user>\w+)@(?<site>\w+)\.com, the replacement can be written $<user> at $<site>, which is easier to read later.
Tips
- Start simple and grow. Match a fixed word first, then add classes and quantifiers one at a time.
- Escape special characters like
. ? + * ( ) [ ] { } | \ ^ $with a backslash when you mean them literally. A plain.inexample.commatches any character. - Use anchors and boundaries.
\bstopscatmatching insidecategory. - Avoid catastrophic backtracking. Nested quantifiers like
(a+)+$can take exponential time on text that almost matches. Make inner parts more specific. - Don't parse HTML or JSON with regex. Use the JSON Formatter for JSON, and real parsers for HTML.
- Compare before and after a replace with the Text Diff Checker.
- Writing Apache redirect rules? Test the path pattern here, then generate the rule with the .htaccess Redirect Generator.
Limitations
- This is the JavaScript flavour. Most syntax is shared with PCRE (PHP), Python and Java, but features like possessive quantifiers (
a++), atomic groups and\A/\Zanchors don't exist in JavaScript, and lookbehind support varies in older browsers. - The common patterns are practical starting points, not perfect validators. The email pattern, for example, accepts most real addresses but not every address the email standard allows.
- Very slow patterns can still pause the page briefly before results appear.
For scheduling patterns rather than text patterns, see the Cron Expression Builder.
Frequently asked questions
Which regex flavour does it use?
Your browser’s JavaScript (ECMAScript) engine. Most syntax matches PCRE and Python, but some features, such as possessive quantifiers, differ.
Why do I only get one match?
Add the g (global) flag to find all matches instead of the first one.
What do the m and s flags do?
m makes ^ and $ match at each line break. s lets the dot match newline characters too.
Can a regex freeze the page?
Patterns with nested quantifiers, such as (a+)+, can take exponential time on some inputs. The tester limits the number of matches it shows to stay responsive.
Last updated: . Written and tested by Abdul Moid Khan, ATechCraft. Read how we build and test tools.