About the Regex Tester
Regular expressions are powerful but easy to get subtly wrong. This regex tester runs your pattern with JavaScript's built-in RegExp engine against sample text and highlights every match, so you can see exactly what a pattern catches before you put it in code.
How it works
The tool builds a RegExp object from your pattern and flags. With the g (global) flag, it calls exec repeatedly to collect every match and its position; if a match is empty, it advances one character so the loop always finishes. Without g, only the first match is found.
Each match is then wrapped in a highlight inside a copy of your test text, while the text between matches is shown unchanged. If the RegExp constructor throws an error, that message is displayed instead of a match count.
How to use
- 1
Type your pattern between the slashes, or pick one from Common patterns.
- 2
Click the flag buttons to turn g, i, m, s, u or y on and off.
- 3
Paste or type sample text in the Test string box.
- 4
Check the highlighted matches and the table of each match with its position and capture groups, or switch to Replace to try a replacement.
Worked examples
Find all numbers
Pulling numbers out of a sentence.
Case-insensitive search
Finding every form of a word.
Without the global flag
Only the first capitalized word.
Frequently asked questions
Does this support different regex flavors?+
No. It uses JavaScript's RegExp engine, so features specific to PCRE, Python or Java, such as possessive quantifiers, may not work or may behave differently.
How do I test regex flags like case insensitivity?+
Click the flag buttons under the pattern. For example, turn on g and i to find all matches and ignore case.
Why does my pattern only match once?+
Without the g flag, JavaScript stops at the first match. Turn on the g flag to find every match.
Do I need to type the slashes?+
No. The slashes are shown for you; type only the pattern itself.
What does 'Invalid regular expression' mean?+
The pattern has a syntax error, such as an unclosed bracket or a quantifier with nothing before it. The message from the engine usually names the problem.