Regex Tester
Test regular expressions with live highlights, groups and replace.
What is a regex tester?
A regular expression, or regex, is a small pattern language for finding text. With one line you can match every email address, phone number or date in a document, check that a user name has the right format or reformat thousands of lines at once. Regex syntax is compact and easy to get slightly wrong, so a tester lets you try a pattern against sample text and see exactly what it matches before using it in code.
This tester uses your browser’s built-in JavaScript regex engine, so results match what you will get in JavaScript, TypeScript and Node.js.
How to test a regular expression
- Type your pattern without the surrounding slashes.
- Turn on the flags you need, such as
gfor all matches andito ignore case. - Paste the text you want to search. Matches are highlighted as you type.
- Check the match table for the position of each match and the value of every capture group.
- Enter a replacement to preview the result of a search and replace.
Features
- Live highlighting with alternating colours so neighbouring matches are easy to tell apart.
- Match table listing each match, its index and numbered and named groups.
- Replace preview supporting
$1,$<name>and$&. - All JavaScript flags: g, i, m, s, u and y.
- Cheat sheet of the most used syntax, one tap away.
- Clear error messages when a pattern is invalid.
Understanding flags
The g flag finds every match instead of stopping at the first. i ignores the difference between upper and lower case. m makes ^ and $ match at the start and end of each line. s lets the dot match line breaks. u enables full Unicode support, including \p{L} for any letter. y only matches at the exact position where the previous match ended.
Tips for writing better regex
Start small and add pieces one at a time, watching the highlights change. Use named groups such as (?<year>\d{4}) to make patterns self documenting. Prefer specific character classes like [^"]* over .*, which is greedy and can match far more than you expect. Avoid nested quantifiers such as (a+)+, which can make the engine slow down dramatically on long text. Finally, test with text that should not match as well as text that should. Once the pattern works, use the Copy regex button to copy it in /pattern/flags form, ready to paste into your JavaScript code.
Frequently asked questions
Which regex flavour does this tester use?
It uses the JavaScript engine built into your browser. Most syntax is shared with PCRE, Python and Java, but some features such as possessive quantifiers are not available.
Why is only one match shown?
Without the g flag, a JavaScript regex stops at the first match. Tick the g flag to find all matches.
Is there a limit on matches?
The highlighter shows up to 1,000 matches and the table lists the first 200, which keeps the page fast on large texts.