Regex Tester

Test JavaScript regular expressions against your own text with live match highlighting and a replace preview — instantly, in your browser.

Flags
  • Free — No signup required
  • Instant — Results update as you type
  • Private — Processed in your browser

A regular expression that works in your head and one that works on real input are often two different patterns. This tester compiles your pattern with the browser's own RegExp engine, highlights every match in the text you paste, lists capture groups, and previews a replacement, so the feedback loop is a keystroke rather than a deploy.

How it works

Type a pattern without the surrounding slashes and tick the flags you need. The pattern is compiled with new RegExp(pattern, flags); a syntax error shows the engine's message immediately. As you edit the test string, matches are found with String.matchAll, highlighted inline, and listed with their start index and capture groups. Named groups such as (?<year>\d{4}) are captured too.

The match list always searches globally, even when the g flag is unchecked, because a list of one match is not much of a list. Searching stops after 500 matches, and the list below the highlight shows the first 50. The replace preview is different: it calls String.replace with your flags exactly as chosen, so without g only the first occurrence is replaced, which mirrors what your code will do. The replacement string supports $1, $<name>, $& for the whole match and $$ for a literal dollar sign.

Everything runs in your browser; text and patterns are never sent anywhere.

The flags

  • g affects only the replace preview here, but in code it also changes test and exec to remember their position between calls, a frequent source of alternating true/false results.
  • i ignores case. With u it also folds Unicode case correctly.
  • m makes ^ and $ match at line boundaries instead of only at the ends of the whole string.
  • s lets . match newlines, which it otherwise does not.
  • u switches to Unicode mode: \u{1F600} escapes, \p{Letter} property classes, and correct handling of characters outside the Basic Multilingual Plane, which are otherwise seen as two units.
  • y anchors each match at the position where the previous one ended.

JavaScript is its own flavour

Patterns copied from grep, sed, Python or Java mostly work, but not always. JavaScript has lookahead and lookbehind, non-greedy quantifiers, named groups and Unicode properties. It does not have possessive quantifiers, atomic groups, \A and \Z anchors, or POSIX classes such as [[:digit:]], and the pattern-wide (?i) modifier is not accepted (the scoped form (?i:…) only works in recent engines). Backreferences use \1 in the pattern and $1 in the replacement, not \1 in both as in sed.

Zero-width matches are legal: a* matches the empty string at every position of bbb, which is why a badly anchored pattern can report more matches than there are characters. The highlighter marks these as thin markers so you can see where they landed.

Catastrophic backtracking

Nested quantifiers over overlapping classes, for instance (\w+\s?)+$ against a long line that does not end as expected, make the engine try an exponential number of paths. In this tool the symptom is a frozen tab; in production it is a denial of service triggered by one crafted input. Prefer specific character classes to .*, avoid quantifying a group that already contains a quantifier, and anchor patterns so failure is detected early.

Command-line equivalent

The nearest equivalent of the match list is grep -oE, which prints each match on its own line; note that grep uses POSIX extended syntax rather than JavaScript's:

grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}' access.log | sort | uniq -c

Learn more

The guide to text processing with grep, sed and awk covers the POSIX dialects and how their syntax differs from what you test here. For the language side, JavaScript fundamentals explains the string methods that consume these patterns and how replace callbacks give you more control than a replacement string. If your input is JSON rather than free text, the JSON formatter will pretty-print it so line-based patterns have something to bite on.

FAQ

Which regex flavor does this use?
JavaScript's native RegExp engine — the same one used by String.match, String.replace and every browser and Node.js runtime.
Why does the match list show more matches than I expected?
The match list always searches globally so it can show every occurrence, regardless of whether you've checked the g flag. The g flag still controls whether the replace preview changes one match or all of them, matching real .replace() behavior.
Is my text uploaded anywhere?
No. Matching happens entirely in your browser.