Regex Tester

Test JavaScript regular expressions against sample text — see every match with its position, toggle flags, and get clear errors for invalid patterns.

Flags
—

How it works

A regular expression is a compact pattern language for describing text: \w+ matches a run of word characters, \d matches a digit, . matches (almost) any character, and parentheses capture parts of the match for later use. Flags change how the pattern behaves — g finds every match instead of stopping at the first, i ignores letter case, and m makes ^ and $ anchor to line boundaries rather than the whole string. Each match below is listed with its index, the character position where it starts, which is handy when slicing strings in code. If the pattern has a syntax error, the JavaScript engine's own message is shown so you can fix it. The test string is capped at 20,000 characters and matches at 500 to keep pathological patterns from freezing your tab.

How to use

Everything updates live as you type — no run button needed:

  1. Type your pattern into the Pattern field. It comes preloaded with (\w+)@(\w+\.\w+), an email-matching pattern you can experiment with immediately.
  2. Paste or type your sample text into the Test string box — the page includes three lines of example emails to test against.
  3. Toggle the flags: g finds every match instead of stopping at the first, i makes matching case-insensitive, and m lets ^ and $ anchor to each line instead of the whole string.
  4. Read the results below the test string. Each match is listed with its starting character index; if the pattern has a syntax error, the JavaScript engine's own error message appears so you know exactly what to fix.

Frequently asked questions

Which regex flavor does this tester use?

JavaScript (ECMAScript), the same engine that runs in every browser. That means \d, \w, \s, character classes like [A-Za-z], quantifiers like + * ? {3}, groups, and lookaheads all behave exactly as they would in your web code.

What is a good example pattern to learn with?

Try \d{3}-\d{4} against text containing 555-1234. Here \d means any digit, {3} means exactly three of them, - matches a literal hyphen, and \d{4} matches four digits — so the whole pattern finds a seven-digit phone-number fragment. Add parentheses like (\d{3})-(\d{4}) to capture the two halves separately.

Why does my pattern find no matches?

The most common causes are case sensitivity (enable the i flag), a special character that needs escaping (a literal dot is \., not .), or anchors like ^ and $ without the m flag on multi-line text. Check the match list and adjust one thing at a time.

What is the match index?

The index is the character position where each match starts, counting from 0. It is the same offset JavaScript's string methods use, which makes it easy to copy a match position straight into slice(), substring(), or matchAll() code.