Regex Tester - Test Regular Expressions

Test a real regular expression against real text, with live match highlighting and capture group output - powered by your browser's actual JavaScript regex engine.

Test Regular Expressions

JAVASCRIPT REGEXP ENGINE

Test matches, capture groups, positions and replacements in your browser.

LOCAL · NO INPUT UPLOAD
READY — Edit the pattern or test text to see actual browser regex results.

Pattern & Flags

Flags: d g i m s u v y. Duplicate, unknown and incompatible (u + v) flags are rejected by your browser.

Try example:

Test String

MAX 100,000 UTF-16 CODE UNITS
MATCHES SHOWN—
FIRST MATCH INDEX—
ENGINE TIME—

Match Highlighting

ACTUAL MATCHES
Order #1042 paid; order #1043 pending.

Marked spans are literal matches. A ¦ marker represents an empty/zero-width match. Positions use JavaScript UTF-16 code units (0-based).

Matches & Capture Groups

FIRST 300 MAX
Run the test to inspect exact captures.

Replacement Preview

$& entire match · $1 first group · $<name> named group · $$ literal dollar. Replacement follows JavaScript String.replace() rules (without g, first match only).

Accuracy & privacy: This widget uses your browser's real JavaScript regex engine inside a Web Worker, with a 1.8-second timeout and a 300-match display limit. A timeout means INCONCLUSIVE, not “no matches.” The widget does not send input to an API. If your browser or site policy blocks Blob-backed Workers, execution is explicitly unavailable. Catastrophic backtracking can still use CPU briefly before the Worker is terminated. Page-level resources/analytics are separate from this tool.

★ ★ ★ ★ ★
No ratings yet — be the first

What Is a Regex Tester?

A regex tester lets you try a regular expression against sample text and inspect what the browser actually matches. This tool uses the JavaScript RegExp engine to highlight literal matches, show exact zero-based UTF-16 positions and capture groups, and preview JavaScript replacement strings. It evaluates patterns locally inside an isolated Web Worker and cancels work that exceeds its short time limit. It does not simulate Python, PCRE or other regex engines.

How to Use the Regex Tester

  1. Enter your pattern: type the raw expression without outer / characters, for example order\s+#(?<id>\d+). Choose a built-in example for a quick start.
  2. Choose JavaScript flags: enter flags such as g (all matches), i (ignore case), m (multiline anchors), s (dot matches newline), u/v (Unicode modes), d (capture indices) or y (sticky matching). Use flag buttons or edit the field. Combining u with v is invalid.
  3. Supply test text: paste or type the actual sample in the Test String box. Edits automatically re-run the evaluation, or use Run Test. Input is limited to 100,000 UTF-16 units.
  4. Inspect results: highlighted spans are exact matches; a small ¦ marks an empty/zero-width match. The match list shows full text, start/end positions, numbered captures and named groups. With the d flag, group indices are also available where the browser supports them.
  5. Try replacement: type a replacement using JavaScript tokens such as $&, $1, $<id> or $$. The output follows native String.replace() rules; without g, it replaces at most one match.
  6. Export or stop: copy replaced text, copy a JSON report or download the report locally. Stop terminates a running check. A timeout or blocked Worker is an inconclusive/unavailable result, not a claim of zero matches.

How It Works

Each run creates a browser RegExp using exactly your pattern and flags in a Web Worker. The engine calls exec() and records match strings and capture groups; the g flag allows repeated scanning, while y anchors matching at the current lastIndex. Empty matches advance by one Unicode code point in u or v mode (otherwise one UTF-16 unit) to prevent infinite loops. Matching stops after 300 displayed results, so “300+” never asserts an exact total.

The replacement preview calls native String.replace() with a separately constructed regex to avoid altering the scanning state. A Worker timeout of 1.8 seconds terminates the evaluation attempt and reports INCONCLUSIVE. The page updates the highlighted view using text nodes rather than injecting raw user input as HTML. Pattern, test data and replacement stay in your browser during tool execution.

Understanding Your Results

  • MATCHES FOUND: actual JavaScript matches for this expression and input. Without g, only the first match is requested, so the number is not a whole-text match count.
  • NO MATCHES: the Worker finished the test normally and the expression did not match in this run. With y, the pattern may fail at index 0 even if it could match further into the text.
  • Capture groups: the group list preserves strings and undefined for optional groups that did not participate. With d the reported ranges are end-exclusive.
  • Zero-width matches: a visual ¦ marks positions where a regex matched an empty string; the original text is not replaced with a character.
  • TIMEOUT / INCONCLUSIVE: evaluation exceeded 1.8 seconds; it is not evidence of a non-match or of a safe regex. Review nested quantifiers and shorten inputs.
  • Worker unavailable: browser support or restrictive Content Security Policy prevented isolated execution; no result is invented.

Browser Limitations

The tester uses the browser's implemented ECMAScript regex features; advanced v Unicode sets and d indices depend on browser version. JavaScript strings and RegExp.exec() index in UTF-16 code units, not user-perceived characters; supplementary symbols such as emoji occupy two units. Backtracking may consume CPU until the Worker is terminated. A Worker timeout is a local responsiveness safeguard, not a guarantee that every unsafe pattern is detected. Restrictive CSP settings can block Blob-backed Workers; in that case the tool reports unavailable rather than attempting risky main-thread execution. The widget does not submit inputs to an external server; the website may still load its normal assets/analytics.

Common Mistakes to Avoid

  • Expecting every match without the g flag: a pattern without g returns a single result; adding g requests global scanning.
  • Confusing g with y: global searches ahead for the next match; sticky searches only at the exact next position.
  • Not escaping metacharacters: ., *, ?, +, parentheses and brackets have regex syntax roles.
  • Copying Python/PCRE-only syntax: this is specifically JavaScript regular-expression syntax, which differs across programming languages.
  • Ignoring zero-width matches and Unicode positions: an empty match does not consume a character and indices count UTF-16 units, not grapheme clusters.
  • Treating a timeout as a successful safety test: a timed-out pattern is simply inconclusive; simplify the pattern rather than assuming it is safe.

Frequently Asked Questions

Why do I need to add the "g" flag to find all matches?

Without g, the tester reports only the first engine match. The global flag requests repeated matching up to this tool's 300-match display limit. The y sticky flag differs because it matches only at the current position.

What's the difference between a match and a capture group?

The match is the entire substring selected by the regex. Parenthesized capture groups extract parts of that substring, including numbered or named captures; optional non-participating groups are shown as undefined.

Is my regex pattern or test text sent to a server?

No. This widget runs its RegExp and replacement operations in a local browser Worker and prepares reports locally. The website itself may load normal assets and analytics separately.

Does JavaScript regex work exactly like Python or other languages' regex?

No. While many basic expressions are similar, advanced syntax, Unicode rules and replacement tokens differ by engine. This tool uses the browser's JavaScript RegExp behavior.

Why does my pattern seem to hang on long text?

Backtracking-intensive regex patterns can take very long to evaluate. This tester attempts to terminate evaluations after 1.8 seconds in a Worker and reports the outcome as inconclusive; simplify nested quantifiers or reduce test input.

Conclusion

The Regex Tester makes JavaScript pattern behavior easier to debug with real match highlighting, capture groups, replacement previews and transparent timeout limits. To validate and format structured data after extracting it, try the JSON Formatter & Validator.