Regex Tester

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.

About this tool

What is the Regex Tester?

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.

How to use

  1. Enter a Pattern without the surrounding slashes, for example \d{4}-\d{2}, or choose one from Presets.
  2. Toggle the Flags you need. Without g, only the first match is found.
  3. Type or paste text into Test string. Matches are highlighted under Highlight and listed under Matches.
  4. To test a substitution, switch from Match to Replace, enter a Replacement, and copy the Result.
  5. Look at Diagram to see the pattern as a Railroad diagram, or switch to NFA or Minimal DFA for a state diagram.

Features

  • Color-coded highlighting: the whole match and each capture group have their own color, with a legend
  • Match details: index range, length, and every numbered and named group with its position
  • All flags: g global, i ignore case, m multiline, s dotAll, u unicode, v unicode sets and y sticky (hover a flag for a description)
  • Replace preview using JavaScript replacement patterns
  • Presets: email address, URL, IPv4 address, date, time, Japanese phone numbers and postal codes, hiragana, katakana, kanji and more
  • Error messages from the engine for invalid patterns
  • Backtracking protection: matching runs in a Web Worker and stops after 1 second, so a pattern like (a+)+ cannot freeze the page
  • Copy all matches, one per line
  • Regex visualizer: the pattern drawn as a railroad diagram, an NFA or a minimal DFA, downloadable as SVG

Railroad diagram (regex visualizer)

The 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:

  • Literal text is shown in quotes, and consecutive characters are joined, such as “http”
  • Escapes are spelled out in green pills: \d is digit, \w is word char, . is any char except newline (or any char with the s flag)
  • Character classes are dashed frames tagged any of or none of, listing their characters and ranges
  • Alternatives (|) 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)
  • Capturing groups are framed with a tab such as #1 year, lookarounds are dashed frames such as lookahead, and anchors (^ start, $ end, \b boundary) and backreferences (\1 → #1) have their own boxes

Automaton diagram (regex to NFA / DFA)

Every 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.

ViewWhat it shows
NFAA 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 DFAThe 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.
  • Character sets follow the flags exactly: i (both cases), s (. includes line breaks), u / v (code points, \p{...} properties and set operations).
  • The DFA accepts strings that match the whole pattern; ^ and $ are treated as if the pattern were anchored at both ends.
  • Patterns whose automaton is very large (over 400 NFA states or 200 DFA states), such as a{1,1000} or (a|b)*a(a|b){10}, are not drawn.

Replacement patterns

PatternInserts
$&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.

FAQ

Why do I only get one match?

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.

Why does my pattern from Python or PHP not work?

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>...).

What does "Matching took longer than 1 second" mean?

The pattern probably causes catastrophic backtracking, often from nested quantifiers such as (a+)+ or (.*)*. Make the inner part more specific or remove the nesting.

Can I convert a regular expression to a DFA?

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.

Why is there no DFA for my pattern?

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.

Is my test text sent anywhere?

No. Matching and replacing run in your browser only.

Limits

  • Up to 5,000 matches are counted and the first 200 are listed in detail.
  • The highlight view shows the first 100,000 characters of the test string.
  • Zero-length matches are shown as thin markers and do not cause infinite loops.