What is a regex tester?
Regular expressions (regex) are compact patterns for finding and manipulating text: validating email addresses and phone numbers, extracting dates from logs, cleaning up CSV files or doing powerful search-and-replace in a code editor. They are also famously easy to get subtly wrong. A tester lets you try a pattern against sample text and see the results immediately, before you put it into code.
This tester uses your browser's own JavaScript regex engine, so results match exactly what String.prototype.match, matchAll and replace will do in your code. Matching runs in a background worker, so even a runaway pattern cannot freeze the page; it is stopped after 1.5 seconds with an explanation.
How to use it
- Type your pattern between the slashes. Do not include the slashes or flags in the box.
- Tick the flags you need, for example
gto find all matches andito ignore case. - Paste sample text into the test string. Matches are highlighted as you type.
- Check the table for each match's position and capture groups, and enter a replacement to preview the result of
replace().
Quick reference
| Pattern | Meaning |
|---|---|
\d \w \s | Digit, word character, whitespace (uppercase = the opposite) |
. | Any character except a newline (any character with the s flag) |
* + ? {2,5} | 0 or more, 1 or more, optional, between 2 and 5 times |
^ $ \b | Start, end (of each line with m), word boundary |
[abc] [^abc] | Any of a, b or c; anything except them |
(…) (?<name>…) (?:…) | Capture group, named group, non-capturing group |
(?=…) (?!…) | Lookahead: followed by / not followed by |
Example
The sample pattern ([A-Z][a-z]+) ([A-Z][a-z]+) with the g flag finds two capitalised words in a row. In the sample text it matches “Ada Lovelace”, “Alan Turing” and “Grace Hopper”, capturing the first name in group 1 and the surname in group 2. The replacement $2, $1 swaps them, so the first line becomes “Lovelace, Ada was born in 1815.”
Change the pattern to \d{4} to find the three years instead, or to (?<year>\d{4}) to see a named group in the match table.
More worked examples
Find dates: the pattern \d{4}-\d{2}-\d{2} with the g flag matches ISO dates such as 2026-10-24 in a log file.
Common mistakes to avoid
- Forgetting the g flag. Without it, JavaScript stops after the first match.
- Writing nested quantifiers. Patterns like (a+)+ can hang on long input; the tester stops them after 1.5 seconds.
- Escaping for the wrong context. In a JavaScript string, backslashes must be doubled. To compare outputs, use the text diff checker.
Sources and methodology
The calculations on this page follow these published standards and references. The code is covered by automated tests against known values.