Developer GUIDE

Regex Testing and Replacement Guide

Inspect JavaScript matches and capture groups, preview replacement syntax, and understand worker timeout limits.

Updated About 2 min read
Open Regex Tester & Debugger

Test JavaScript regular expressions

The Regex Tester & Debugger matches a pattern against local text, highlights matches, explains captured values through match details, and previews replacements. It is useful for extracting values from logs, refining a search expression, or removing repeated whitespace. It uses your browser's JavaScript regular-expression engine; another language or engine may behave differently.

Enter a pattern and choose flags

Enter the pattern without slash delimiters. The supported flag controls include global matching, case insensitivity, multiline anchors, dot-all behavior, Unicode handling, sticky matching, and capture indices when the browser supports them. Unsupported flags are not offered. An invalid expression produces an error without clearing your input or crashing the page.

Global matching searches for successive matches. Without global or sticky flags, the tool reports the first match. Sticky matching requires the next match to begin at the current index and stops when that position does not match. Multiline mode changes how start and end anchors treat lines; dot-all changes whether a dot matches line breaks. Unicode mode affects surrogate-pair handling and zero-width progress.

Each match records the matched text and its start and exclusive end indices. JavaScript indices count UTF-16 code units, so a supplementary Unicode character can occupy two positions. Match details include numbered and named captures; unmatched optional groups are null. With the indices flag, capture ranges are also shown. Highlighting renders text safely through React rather than inserting user HTML.

Preview replacements

Enable replacement mode and enter the replacement string. Standard JavaScript tokens include

amp; for the full match, $1 for a numbered capture,
lt;name>
for a named capture, and $ for a literal dollar sign. Prefix and suffix tokens are supported too. The preview leaves the original test text unchanged.

For example, load the date-shaped preset. Its named year, month, and day groups let

lt;day>/
lt;month>/
lt;year>
rearrange a date-like string. This pattern checks shape, not whether a date exists. Likewise, email-like and URL-like examples are practical patterns, not universal validators. The numbers, whitespace cleanup, and duplicate-word presets provide other starting points.

Keep evaluation bounded

Live evaluation waits 300 milliseconds after edits and runs in a disposable worker. Patterns are limited to 2,000 characters, test text to 50,000, replacement text to 10,000, and replacement output to 200,000. Above 20,000 test-text characters, live evaluation pauses until you choose Run regex.

A worker is terminated after one second, cancellation, input replacement, or unmount. Expensive backtracking produces Pattern took too long to evaluate rather than blocking the interface. This is a time budget, not a perfect ReDoS detector. At most 500 matches and bounded capture data are displayed; replacement is disabled when results are truncated, because replacing only some matches would misrepresent the result.

No user input is evaluated as JavaScript source, transmitted, logged, or stored. Clear/reset discards the workspace. Use JSON Formatter + Validator, Encoder & Decoder, or Secure YAML Builder for related data preparation.

Ready to try it?

Regex Tester & Debugger

Inspect JavaScript matches and capture groups, preview replacement syntax, and understand worker timeout limits.

Open Regex Tester & Debugger

Related tools

Related resources