Regex Tester
Test regular expressions live with match highlighting and replace preview.
Your files never leave your device. Everything runs in your browser.
What Regex Tester does
Regex Tester runs a JavaScript regular expression against sample text and shows every match highlighted in place. The pattern, flags, test text and an optional replacement are all editable, and the results update as you type.
It is built for the fiddly part of writing regular expressions: checking that a pattern matches the right things and that it does not match the wrong ones. Paste a log line, a list of email addresses, a snippet of HTML or test data, then refine the pattern and watch the highlights and match list change. A pattern such as “\b\w+@\w+\.\w+\b” over “Contact [email protected] or [email protected]” reports two matches, at indexes 8 and 27.
The match counter shows how many matches were found, each row in the match list shows the matched text, its starting index and any captured groups, and adding a replacement previews the substituted result. Everything runs on the browser's regular expression engine.
How to use Regex Tester
- Enter the pattern in the Pattern field and the text to search in Test text.
- Tick the flags you need: g (global, on by default), i (ignore case), m (multiline), s (dot matches newlines) and u (Unicode).
- Read the highlight — every match is marked in the text, or only the first without the g flag — and check the match count above it.
- The match list below shows each match's text, starting index and capture groups; the first 20 are listed while the counter shows the total.
- Type a replacement in Replace with to preview the result, using $1, $2 and $& in the same way JavaScript's replace does.
- Click Copy result to copy the replaced text — it works once a replacement has been entered.
Features
- Live testing: the pattern, flags, test text and replacement all re-run as you type.
- Five flags: global, ignore case, multiline, dotAll and Unicode.
- Match highlighting plus a numbered match list showing matched text, index and capture groups, with the first 20 matches listed.
- Replacement preview using JavaScript's substitution patterns, with a copy button.
- Invalid patterns show the engine's own error message instead of failing silently.
- Zero-length matches are handled safely, so a pattern such as “a*” advances through the text instead of looping forever.
Tips and common mistakes
- The tester uses JavaScript's engine. Patterns written for Python, PCRE, Java or .NET can differ: possessive quantifiers and some inline modifiers are not standard JavaScript regex.
- There is no timeout or worker around the matching loop. A pattern with severe backtracking — nested quantifiers like “(a+)+” are the classic example — can freeze the tab on unlucky input, so test suspicious patterns on short strings first.
- The g flag controls both the highlighting and the replacement preview: without it, only the first match is found and only the first match would be replaced.
- Empty matches are legitimate. “a*” over “bab” reports four matches — an empty match at position 0, “a” at position 1, and empty matches at positions 2 and 3.
- Watch invisible characters. A pattern searching for a space will not match a tab or a non-breaking space, which is a common cause of “it should match but does not”.
Frequently asked questions
Which regex flavour is this?
The browser's JavaScript engine — ECMAScript regular expressions, the same syntax used in web development and Node.js. Python, PCRE, Java and .NET support different syntax and additional features, so patterns do not always transfer.
Why does my pattern return only one match?
The g (global) flag is off. With g ticked, every non-overlapping match is found; without it the engine stops at the first. The flag also decides whether a replacement affects one match or all of them, and g is on by default.
What does each flag do?
i ignores case, m makes ^ and $ match at line breaks rather than only the start and end of the whole text, s lets the dot match newline characters, and u switches on Unicode mode. g finds all matches instead of just the first.
Can a bad pattern hang the page?
Yes. JavaScript regex has no execution limit and the tester does not run patterns in a worker or with a timeout, so a pattern that backtracks catastrophically — nested quantifiers applied to a long, nearly matching string — can freeze the tab until the browser stops it. Keep the test text short while developing such patterns.
Does it support named groups and lookbehind?
Patterns are passed straight to your browser's engine, so support follows the browser: current versions of Chrome, Firefox, Safari and Edge support named groups and lookbehind.
Can I test a replacement?
Yes. Type into Replace with and the replaced text appears in a read-only preview; Copy result copies it. Capture-group references such as $1 and the whole-match reference $& follow JavaScript substitution rules.
Related text tools: Find & Replace, Text Diff Checker, Line Tools, Word Counter.
Patterns and test text are processed in your browser; nothing is uploaded.