What is regex testing?
Regular expressions (regex) are patterns used to match character combinations in strings. This tool lets you write a regex pattern and test it against sample text with instant visual highlighting of matches, captured groups, and match indices. All processing runs in your browser using JavaScript's native RegExp engine.
How a regular expression works
A regular expression is a pattern that describes a set of strings. The engine reads your pattern left to right and tries to match it against the input text. Literal characters match themselves, while metacharacters like ., *, +, and ? describe repetition, position, and choice. When the pattern matches, the engine reports the matched text, its position, and the contents of any capture groups.
This tester uses JavaScript's native RegExp engine, so patterns behave exactly as they do in JavaScript and TypeScript. Matches are highlighted as you type, and capture groups are listed so you can see precisely what each part of your pattern captured.
Regex flags
Flags change how the whole pattern is applied. The global flag (g) finds every match instead of stopping at the first. The ignore-case flag (i) makes matching case-insensitive. The multiline flag (m) makes ^ and $ match at line breaks. The dotAll flag (s) lets . match newline characters. Combine flags as needed — for example gi to find all matches regardless of case.
Common regex mistakes
A few mistakes account for most broken patterns: forgetting to escape a literal dot or slash, relying on greedy quantifiers when a lazy one is needed, and omitting the global flag when you expect every match. Character classes are another trap — inside square brackets most metacharacters lose their special meaning, so [.] matches a literal dot, not any character.
When a pattern matches too much or too little, test it against several inputs — including edge cases and empty strings — and check the capture groups to see exactly what each part of the pattern consumed.
How to test a regular expression
- 1Enter your pattern. Type your regex into the pattern field — you do not need the surrounding slashes.
- 2Set flags. Enable flags such as g (global), i (ignore case), or m (multiline) to control how the pattern is applied.
- 3Add test text. Paste the text you want to search. Matches are highlighted in real time as you type.
- 4Inspect matches and groups. Review each match, its index, and any captured groups to confirm the pattern behaves as intended.
- 5Use Replace. Switch to Replace to preview how your pattern rewrites the text, using $1, $2 to reference capture groups.
Examples
Match an email address
Tested against: contact ada@dev-toolbox.io
Input
[\w.+-]+@[\w-]+\.[\w.-]+
Output
ada@dev-toolbox.io
Capture date parts
Tested against: 2026-09-13
Input
(\d{4})-(\d{2})-(\d{2})Output
Group 1: 2026 · Group 2: 09 · Group 3: 13
Find all hashtags
Flag: g — tested against: #dev #tools #seo
Input
#\w+
Output
#dev, #tools, #seo
Match a US phone number
Tested against: (415) 555-0132
Input
\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}Output
(415) 555-0132
Regex quick reference
The most common tokens, as matched by JavaScript's RegExp engine.
| Token | Matches |
|---|---|
| \d | Any digit (0–9) |
| \w | Word character (a–z, A–Z, 0–9, _) |
| \s | Whitespace (space, tab, newline) |
| . | Any character except newline |
| ^ / $ | Start / end of string (or line with m) |
| * | 0 or more of the preceding |
| + | 1 or more of the preceding |
| ? | 0 or 1 (optional) |
| {n,m} | Between n and m repetitions |
| [abc] | Any one of a, b, or c |
| [^abc] | Any character except a, b, or c |
| (...) | Capture group |
| a|b | a or b (alternation) |
| \b | Word boundary |
Frequently asked questions
Which regex flavor does this use?+
The JavaScript (ECMAScript) RegExp engine. Patterns you test here behave identically in JavaScript, TypeScript, and Node.js. Syntax differs slightly from PCRE, Python, or Java regex.
What are capture groups?+
Parentheses ( ) create a capture group that remembers the part of the match inside them. Groups are numbered left to right and can be referenced in replacements as $1, $2, and so on.
What is the difference between greedy and lazy matching?+
Quantifiers like * and + are greedy by default — they match as much as possible. Adding ? after them (*?, +?) makes them lazy, matching as little as possible. This matters when a pattern could match several lengths.
What do the flags g, i, m, and s do?+
g finds all matches instead of the first; i ignores case; m makes ^ and $ match at line breaks; s (dotAll) lets . match newlines. They can be combined, such as gi.
How do I match a literal special character?+
Escape it with a backslash. For example \. matches a literal dot, \( matches a literal parenthesis, and \\ matches a literal backslash.
Is my test data private?+
Yes. The pattern and test text are processed in your browser and are never sent to a server.
Is it free?+
Yes — free to use with no sign-up or limits.
Can I use this to replace text with a pattern?+
Yes. Switch to Replace mode, enter a replacement string, and reference capture groups with $1, $2, and so on to rewrite every match.