What it does
The regex tester lets you write a regular expression and see, as you type, exactly what it matches in your sample text. Matches are highlighted in place, every capture group is listed with its value and position, and an optional replacement template shows what String.replace would produce.
How to use
- Paste the text you want to search into Test string, or click Sample.
- Type your pattern into Regular expression in the options panel. Do not add the surrounding slashes.
- Toggle the flags you need: g for all matches, i to ignore case, m for per-line
^and$, s so that.also matches newlines, u for full Unicode. - Read the result: the match count, the highlighted text and a table with each match and its groups. Click Copy to copy any value.
- To try a substitution, fill in Replace with, for example
$2, $1.
Example
The default pattern ([\w.+-]+)@([\w-]+(?:\.[\w-]+)+) finds email addresses and captures the user name and the domain separately. With the replacement $1 at $2, the text hello@example.com becomes hello at example.com.
Quick reference
\ddigit,\wword character,\swhitespace,.any character*zero or more,+one or more,?optional,{2,5}between 2 and 5[abc]one of,[^abc]none of,a|beither(...)capture group,(?<name>...)named group,(?:...)group without capture(?=...)lookahead,(?<=...)lookbehind,\bword boundary
FAQ
› Which regex flavor does this use?
The JavaScript (ECMAScript) engine built into your browser, the same one used by Node.js, Deno and every browser. Most syntax is shared with PCRE, Python and Java, but some features such as possessive quantifiers and recursion are not supported.
› Why does my pattern find only one match?
Turn on the Global (g) flag. Without it, JavaScript stops after the first match.
› How do I refer to groups in the replacement?
Use $1, $2… for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign.
› Why do ^ and $ not match at every line?
By default they match only at the start and end of the whole text. Turn on Multiline (m) to make them match at line breaks.
› Is my text sent anywhere?
No. Matching runs in your browser. Very slow patterns (catastrophic backtracking) can freeze the tab, so avoid nested quantifiers like (a+)+ on long input.