Regex Tester (JavaScript)

Type a pattern and a test string and watch every match, capture group and index update as you type.

Write a pattern and test it

Flags
Matches highlighted
Results
Regex cheat sheet

Character classes

.Any character except a line break
\d \DDigit, non-digit
\w \WWord character [A-Za-z0-9_], non-word
\s \SWhitespace, non-whitespace
[abc]Any of a, b or c
[^abc]Anything except a, b or c
[a-z]A character from a to z
\p{L}Any letter (needs the u flag)

Quantifiers

*0 or more
+1 or more
?0 or 1
{n}Exactly n
{n,}n or more
{n,m}Between n and m
*? +?Lazy: as few as possible

Anchors

^ $Start, end of text (of each line with m)
\b \BWord boundary, non-boundary

Groups and lookaround

(abc)Capturing group
(?<name>abc)Named capturing group
(?:abc)Non-capturing group
a|ba or b
\1 \k<name>Backreference to a group
(?=abc)Positive lookahead
(?!abc)Negative lookahead
(?<=abc)Positive lookbehind
(?<!abc)Negative lookbehind

How to test a regular expression

  1. 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.
  2. Tick the Flags you need: g for every match, i to ignore case, m so ^ and $ work per line, s so the dot matches line breaks, u for Unicode and y for sticky matching.
  3. Paste your text into Test string. Matches are marked in Matches highlighted and listed in Results with their index, length and capture groups.
  4. 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

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.