Regex Tester
Test a regular expression against sample text with live match highlighting and capture groups.
How to use the Regex Tester
- Type your regular expression into Pattern.
- Tick the flags you need: g (all matches), i (ignore case), m (multiline), s (dot matches newlines), or u (unicode).
- Paste sample text into Test string; matches are highlighted and each one is listed with its position and capture groups.
About the Regex Tester
A regex (regular expression) is a pattern used to search, match, or validate text — matching an email format, pulling numbers out of a string, or checking that a password meets certain rules. Regex syntax is compact and easy to get subtly wrong, so testing a pattern against real sample text before using it in code is the fastest way to catch mistakes.
This tool matches your pattern against your test text live as you type, highlighting every match directly in the text and listing each match's position, full matched text, and any capture groups — numbered or named. It uses your browser's built-in JavaScript regex engine, so what you see here behaves exactly like `RegExp` in a JavaScript/TypeScript codebase.
Worked example
Example: the pattern `\\b\\w+@\\w+\\.\\w+\\b` with the global flag matches every email-shaped substring in a block of text — testing it against "Contact hello@kwiktools.app or support@example.com" highlights both addresses and lists them as two separate matches.
Greedy vs lazy matching
Quantifiers like *, +, and {2,} are greedy by default: they match as much text as possible and only give some back if the rest of the pattern fails. Testing <.+> against '<b>bold</b>' matches the entire string, because .+ runs to the last >. Adding a question mark makes the quantifier lazy: <.+?> matches '<b>' and '</b>' separately. A more precise alternative is a negated class, <[^>]+>, which can never run past a closing bracket.
Escaping and moving a pattern into code
Type patterns here exactly as you'd write them between slashes in JavaScript: \d for a digit, \. for a literal dot. When you move a pattern into a string in code — new RegExp("\\d+") in JavaScript, or most other languages' string literals — every backslash has to be doubled, which is the most common reason a pattern that works here fails in code. Characters with special meaning that need a backslash to be matched literally are . * + ? ^ $ { } ( ) [ ] | / and \ itself.
This tester uses JavaScript's regex engine. Patterns that rely on features from other engines, such as possessive quantifiers or atomic groups in PCRE and Java, won't work the same way here.
Patterns that can freeze
Nested quantifiers like (a+)+ or (\w*)* can take an enormous amount of time on text that almost matches, because the engine tries every possible way of splitting the input before giving up. This is called catastrophic backtracking, and in a browser it can freeze the tab. On a server it's a denial-of-service risk. If a pattern hangs, look for a repeated group that contains its own repetition and rewrite it so each character can only be matched one way.
Frequently asked questions
- Why does my pattern only match once, even with repeated matches in the text?
- Without the global (g) flag, JavaScript's regex engine stops after the first match — this mirrors real `RegExp.exec()` behavior, not a bug in this tool. Check the 'g' flag if you want every occurrence found and highlighted.
- What's the difference between numbered and named groups?
- Parentheses like (\\d+) create a numbered capture group, accessible as match[1], match[2], and so on in the order they appear. Writing (?<year>\\d{4}) instead creates a named group, accessible by that name — this tool lists both kinds separately under each match.
- What do the different flags do?
- g (global) finds all matches instead of stopping at the first; i (ignore case) makes matching case-insensitive; m (multiline) makes ^ and $ match the start/end of each line instead of the whole string; s (dot all) makes . match newline characters too; u (unicode) enables full Unicode pattern handling, important for matching characters outside the basic ASCII/BMP range.
- Is my text sent anywhere when I test a pattern?
- No. Matching runs entirely in your browser using JavaScript's native RegExp engine — nothing you type is uploaded, so it's safe to test patterns against real log lines, emails, or other sensitive sample data.