Test JavaScript regular expressions as you type and visualize each pattern as a railroad diagram, an NFA or a minimal DFA. Matches and groups are highlighted. Matches are listed with their positions and replacements are previewed. Includes presets for email, URL, IPv4, dates and Japanese text, plus a timeout that stops runaway patterns.
The Regex Tester runs a regular expression against your test string and shows the result immediately. It uses your browser's own JavaScript (ECMAScript) RegExp engine, so results match what String.prototype.match, matchAll and replace do in JavaScript and Node.js. Other flavors such as PCRE (PHP), Python or Java may behave differently for some features.
\d{4}-\d{2}, or choose one from Presets.g, only the first match is found.g global, i ignore case, m multiline, s dotAll, u unicode, v unicode sets and y sticky (hover a flag for a description)(a+)+ cannot freeze the pageThe Railroad view draws the pattern as a syntax diagram that you read from left to right, between the double bars at the start and the end. It makes long patterns easy to understand at a glance:
“http”\d is digit, \w is word char, . is any char except newline (or any char with the s flag)|) branch into parallel tracks; optional parts get a track above, and repeats a loop below with a count such as 1+, 2–4 or ×3 (lazy for lazy quantifiers)^ start, $ end, \b boundary) and backreferences (\1 → #1) have their own boxesEvery regular expression without backreferences or lookarounds describes a regular language, which a finite automaton can recognize. The Automaton section draws your pattern as a state diagram, which helps to understand what a pattern really accepts, to teach or learn automata theory, and to spot surprises such as an alternative that can never be reached.
| View | What it shows |
|---|---|
| NFA | A nondeterministic finite automaton built from the pattern (Thompson construction, with ε-transitions removed and equivalent states merged). Its shape follows the pattern, and anchors (^, $), word boundaries (\b), lookarounds and backreferences appear as dashed edges |
| Minimal DFA | The deterministic automaton from the subset construction, minimized so that it has the fewest possible states. Edges are labeled with the characters they read, such as a, [a-f], \d or [^,] |
q0 is the start state and double circles are accepting states.i (both cases), s (. includes line breaks), u / v (code points, \p{...} properties and set operations).^ and $ are treated as if the pattern were anchored at both ends.a{1,1000} or (a|b)*a(a|b){10}, are not drawn.| Pattern | Inserts |
|---|---|
$& | The whole match |
$1, $2, … | A numbered capture group |
$<name> | A named capture group |
$` | The text before the match |
$' | The text after the match |
$$ | A literal $ |
Example: pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) with replacement $<day>/$<month>/$<year> turns 2026-10-03 into 03/10/2026.
The g (global) flag is off. Turn it on to find every match; the summary shows "first match only (no g flag)" as a reminder.
Some syntax differs between flavors. For example, JavaScript has no possessive quantifiers (a++) and does not accept a leading (?i) to set flags (use the flag buttons instead), and named groups are written (?<name>...), not (?P<name>...).
The pattern probably causes catastrophic backtracking, often from nested quantifiers such as (a+)+ or (.*)*. Make the inner part more specific or remove the nesting.
Yes. Enter the pattern and choose Minimal DFA under Automaton. The diagram is the smallest DFA that accepts exactly the strings matching the whole pattern, and SVG downloads it as an image.
Backreferences (\1), lookaheads and lookbehinds, and word boundaries (\b) depend on more than the current state, so they cannot be expressed by a finite automaton. The NFA view still shows them, as dashed edges.
No. Matching and replacing run in your browser only.