Regex Tester
Type a regular expression and some text to see every match marked, each one listed with its position and groups, and what a replace would produce.
Type the pattern without the slashes around it, in JavaScript syntax.
Up to 10 million characters. Matching runs in the background and stops after 1.5 seconds.
$1 or $<name> puts in a group, $& the whole match, $$ a dollar sign. Once you’ve typed here, an empty box previews deleting the matches.
Your pattern and text stay on your device: nothing is sent or saved.
Type a pattern and some text to test it.
Matches in the text
Match list
After replacing
Check a regular expression before it goes into your code
A regular expression is a compact pattern for finding text: dates in a log, email addresses in a list, a product code in a file name. Patterns are easy to get almost right. This tester shows exactly what yours matches, so you can fix it before it reaches your code.
How to use it
- Type the pattern without slashes, and tick the flags you need.
- Paste some text. Every match is marked as you type.
- Read the list for each match’s position, line and groups.
- To test a replacement, type it in the replace box, then copy or download the result.
What the flags do
- g finds every match; without it, only the first.
- i ignores case; m makes ^ and $ work on each line; s lets the dot match line breaks.
- u reads whole Unicode characters and allows classes such as
\p{L}; y needs each match to start where the last one ended; d reports where each group starts and ends.
Reading the results
Matches are marked in two alternating colors, so neighbors stay distinct. The list gives each match’s index (counted from 0), its line and column (from 1), and every group, including groups that didn’t take part.
Quick reference
.any character except a line break;\da digit;\wa letter, digit or _;\sa space, tab or line break.[abc]one of a, b or c;[^abc]anything else;[a-z]a range.*zero or more;+one or more;?optional;{2,5}two to five. Add?to take as few as possible.^and$the start and end;\ba word boundary.(…)a group;(?<name>…)a named group;(?:…)a group that doesn’t capture;a|beither.(?=…)and(?!…)followed or not followed by;(?<=…)preceded by.
Good practice
- Anchor when you can. ^ and $ stop a pattern matching inside longer text.
- Escape symbols such as . ? + ( and $ with a backslash to match them literally.
- Avoid repeats inside repeats, such as (\w+)*, which can backtrack for ages.
Good to know
Positions count UTF-16 code units, as JavaScript does, so an emoji counts as two. The list shows the first 1,000 matches. The tester doesn’t check other languages’ syntax or rewrite patterns. To clean a list instead, try Remove Duplicate Lines.