How to test a regular expression
- Type your pattern into Regular expression without the surrounding slashes, or click a preset such as Email or IP address to load a pattern and a sample.
- Tick the Flags you need:
gfor every match,ito ignore case,mso ^ and $ work per line,sso the dot matches line breaks,ufor Unicode andyfor sticky matching. - Paste your text into Test string. Matches are marked in Matches highlighted and listed in Results with their index, length and capture groups.
- If the pattern is not valid, the reason appears under the pattern box in plain words.
How it works
The tester runs your pattern with your browser's own JavaScript regular expression engine, the same one behind RegExp and String.prototype.matchAll in Chrome, Firefox, Safari and Node.js. Syntax follows the MDN regular expressions guide and the ECMAScript specification. Matching runs in a background worker with a one second limit, so a pattern with catastrophic backtracking cannot freeze the page.
Worked example
The default pattern uses named groups to split dates into parts. With the g flag it finds every date in the default test string, and Results shows this:
3 matches
"2026-03-05" at index 24, length 10
year (group 1): "2026"
month (group 2): "03"
day (group 3): "05"
"2026-04-12" at index 39, length 10
year (group 1): "2026"
month (group 2): "04"
day (group 3): "12"
"2026-05-01" at index 66, length 10
year (group 1): "2026"
month (group 2): "05"
day (group 3): "01"
Limits and edge cases
- Indexes count UTF-16 code units, so an emoji takes two positions. With the
uflag, empty matches step over whole characters instead of looping. - An empty match, such as the pattern
x*finds between letters, is shown as "empty match at index N" with a red marker in the highlighted text. - At most 5,000 matches are processed and the first 100 are listed. The test string can hold up to 1,000,000 characters.
- This is the JavaScript flavor. Python, PHP, Java and .NET differ on details such as named group syntax
(?P<name>...), possessive quantifiers, atomic groups and inline flags, so a pattern that works there may need changes here. - The sticky flag
yonly matches at the exact position where the previous match ended, which is why it often finds less thangalone.
Frequently asked questions
What does the g flag do?
The global flag finds every match in the string instead of stopping after the first one. Without it, only the first match and its capture groups are reported.
How do capture groups work?
Anything inside parentheses becomes a capture group, numbered from 1 in the order the opening parentheses appear. Name a group with (?<name>...) and Results shows the name next to its value. Use (?:...) when you need grouping without capturing.
What is the difference between * and +?
The star matches zero or more of the preceding token and the plus matches one or more. That is why a* can match an empty string and a+ cannot.
What is catastrophic backtracking?
Some patterns, such as (a+)+$ on a long run of a letters followed by another character, make the engine try an exponential number of ways to match. This tester stops after one second and tells you, so you can make the inner part more specific.
Matching URLs? Check the encoding with the URL encoder and decoder. To see how a regex replacement changed a document, compare the before and after text in the diff checker, and to validate JSON you extracted, paste it into the JSON formatter. More patterns are in the regex cheat sheet.