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
- Enter your pattern: type the raw expression without outer
/characters, for exampleorder\s+#(?<id>\d+). Choose a built-in example for a quick start. - 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) ory(sticky matching). Use flag buttons or edit the field. Combininguwithvis invalid. - 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.
- 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 thedflag, group indices are also available where the browser supports them. - Try replacement: type a replacement using JavaScript tokens such as
$&,$1,$<id>or$$. The output follows nativeString.replace()rules; withoutg, it replaces at most one match. - 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
dthe 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
gflag: a pattern withoutgreturns a single result; addinggrequests global scanning. - Confusing
gwithy: 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.