What it does
Write a regular expression and see straight away what it matches: every match is highlighted in your text and listed with its position, numbered groups and named groups. The pattern is also explained piece by piece in plain English, so a line like (?<year>\d{4})-(\d{2}) reads as “group 1, named year: a digit, exactly 4 times” instead of a puzzle. Replace mode shows the result of a search-and-replace with $1, $<name> and $& as you type. Matching uses your browser’s own JavaScript engine, the same one that runs your front-end and Node.js code, so what works here works there. A badly written pattern can take minutes to run on some text (catastrophic backtracking); here it’s stopped after 1.5 seconds with an explanation, instead of freezing the page.
How to use it
- Type your pattern between the slashes, or start from one of the examples. Turn flags on or off below it: g finds every match, i ignores case, m makes ^ and $ work per line.
- Paste the text to test. Matches are highlighted as you type, and each one is listed with its position and capture groups.
- Read “What the pattern means” to check each part of your regex in plain English.
- To replace, switch on “Replace” and write the replacement, using $1 or $<name> for groups. Copy the result, or copy the regex itself for your code.
Common uses
- Writing a validation pattern for a form field and checking it against good and bad examples
- Pulling dates, IDs or email addresses out of a log file or a pasted report
- Understanding a regex someone else wrote before changing it
- Testing a find-and-replace with capture groups before running it on a whole codebase
Tips
- Without the g flag, JavaScript stops at the first match. That’s what String.prototype.match and RegExp.exec do in your code too.
- Nested quantifiers like (a+)+ or (\w+\s?)* can backtrack exponentially on text that almost matches. Make each part match something distinct, or use a character class instead of alternation.
- Named groups, (?<name>…), make replacements readable: $<year>-$<month> is easier to check than $2-$1.