Regex Tester
Type a regular expression and some test text, and every match lights up as you type, with a table of positions, numbered groups and named groups. Switch to Replace to preview the result of a replacement before you put it in your code.
PATTERN AND TEST TEXT
MATCHES
Matches show up here as you type.
This uses JavaScript’s regular expressions, the same as browsers and Node.js. PCRE, Python and .NET differ in places, such as lookbehind and possessive quantifiers.
Reading the match table
Each row is one match. The index is where it starts and ends in the text, counted in UTF-16 code units, the same as match.index in JavaScript. Below the match you see every capture group: $1, $2 and so on, plus the name for named groups. A group that took no part in the match, like the unused side of (a)|(b), shows as "not matched", which is undefined in JavaScript.
Replacement patterns
In Replace mode the tester calls JavaScript's String.replace, so the special patterns behave exactly as in your code: $1 to $99 for numbered groups, $<name> for named groups, $& for the whole match, $` and $' for the text before and after it, and $$ for a literal dollar sign. Without the g flag only the first match is replaced.
Common building blocks
\d is a digit, \w a letter, digit or underscore, and \s any whitespace. [a-z] is a range and [^,] anything but a comma. *, + and ? mean zero or more, one or more and optional; add ? after them, as in .*?, to match as little as possible. ^ and $ anchor to the start and end, and \b marks a word boundary.
How to test a regular expression
- 1
Enter the pattern and flags
Type the pattern without slashes, or paste a literal such as /\d+/g and the flags are picked up too. Toggle g, i, m, s, u and y with the buttons. A syntax error shows straight under the field.
- 2
Paste your test text
The matches are highlighted in the text, and the table lists each one with its start and end index and the value of every capture group, by number and by name.
- 3
Try a replacement
Switch to Replace and type the replacement, using $1 for a numbered group, $<name> for a named one and $& for the whole match. The result updates live and can be copied.
Frequently asked questions
Which regex flavour does this tester use?
JavaScript's own RegExp, run by your browser. So a pattern that works here works the same in a browser, Node.js, Deno or TypeScript. PCRE (PHP), Python and .NET are close but not identical; for example they have possessive quantifiers and inline modifiers like (?i) that JavaScript doesn't.
What do the flags g, i, m, s, u and y do?
g finds every match instead of only the first. i ignores upper and lower case. m makes ^ and $ match at the start and end of each line. s lets the dot match line breaks. u turns on full Unicode, needed for \p{L} and \u{1F600}. y (sticky) only matches exactly where the previous match ended.
Why was my pattern stopped?
Some patterns, such as (a+)+$ on a long line of a's, try an exponential number of ways to match before they give up. This is called catastrophic backtracking. The tester runs matching in a separate thread and stops it after a second and a half, so the page stays usable. Rewrite nested quantifiers to remove the ambiguity.
How do I use named groups?
Write (?<year>\d{4}) to name a group. The table shows its value under its number and its name, and in a replacement $<year> inserts it. In code the value is in match.groups.year.
Is my text sent anywhere?
No. The pattern and the text stay in your browser; nothing is uploaded or stored.