Regex Tester Widget

Add a regular-expression tester to your programming tutorial. Readers type a pattern and flags, see every match highlighted in the test text, inspect capture groups in a table and preview a replacement.

Developer Tools Tool Runs in your browser Free · no ads

Customize your widget

Theme
Auto follows the visitor's light/dark setting.
Style
Attribution on your page
Optional and entirely your choice. The exact line is shown in the code below; it links to the tool with rel="nofollow".
More options
Starting values
Leave blank to use the widget's defaults. Visitors can still change every value.

Live preview

Exactly what your visitors will see

Embed code

<iframe src="https://a2z.tools/embed/w/regex-tester" title="Regex Tester by A2Z Tools" width="100%" height="930" style="border:0;width:100%" loading="lazy" allow="clipboard-write"></iframe>

A plain iframe. Works everywhere, including site builders that strip scripts. Adjust height if your content needs more room.

Works with

How it works

The pattern runs in the browser's own RegExp engine, so results are exactly what the reader's JavaScript code will produce, including named groups and the u, s and v flags. With the g or y flag every match is collected (empty matches advance by one character, or one code point with u); without it only the first is shown, as in JavaScript. A browser tab cannot interrupt a regular expression once it starts, so the widget protects the page: the test text is capped at 20,000 characters, at most 1,000 matches are collected and the loop stops after 250 ms. Patterns with a quantified group that itself contains a quantifier - (a+)+ or (\w*)* - are the classic catastrophic-backtracking shape and only run after the reader confirms. Highlighting is built from text nodes, so pasted HTML is shown as text.

Method

  • Engine: ECMAScript RegExp of the visitor's browser; flags d g i m s u v y
  • Global loop: exec until null; empty match -> lastIndex + 1 (code point with u/v)
  • Limits: 20,000 characters of text, 2,000 of pattern, 1,000 matches, 250 ms
  • Replace preview: String.prototype.replace with $1, $<name>, $& substitutions

Limitations

  • Results are for JavaScript only; PCRE, Python re, .NET and POSIX engines differ on lookbehind, possessive quantifiers, atomic groups and Unicode classes.
  • Support for newer syntax (the v flag, duplicate named groups, inline modifiers) depends on the visitor's browser version.
  • The nested-quantifier warning is a heuristic: some slow patterns without that shape still hit the 250 ms stop, and some flagged patterns are harmless.
  • Only one test text is matched; there is no multi-case unit-test list or code generation for other languages.

Where publishers use it

  • JavaScript and TypeScript tutorials on validation patterns
  • Log-parsing guides for DevOps teams
  • Form-validation articles (emails, postcodes, phone numbers)
  • Teaching pages that explain capture groups and lookarounds step by step

Questions

Which regex flavour is this?

JavaScript (ECMAScript). Most syntax matches PCRE, Python and .NET, but features like possessive quantifiers or atomic groups are not available.

Why is my pattern not run straight away?

It contains a nested quantifier such as (a+)+, which can take exponential time on some inputs and freeze the page. Rewrite it, or tick the option to run it anyway.

Why do I only see one match?

Add the g flag. Without it, JavaScript returns only the first match.

Can pasted HTML run in the widget?

No. Text is inserted as text nodes and highlighted with mark elements; it is never interpreted as HTML.

Sources

  1. ECMAScript Language Specification: RegExp (Regular Expression) Objects - Ecma International (TC39) . Pattern grammar, flags and matching semantics the browser implements
  2. ECMAScript: String.prototype.replace and GetSubstitution - Ecma International (TC39) . $1, $<name>, $& and $$ in the replace preview

Cite or recommend this tool

If you reference this tool in an article, course or documentation, these formats are ready to copy. They are optional - nothing is added to your site unless you paste it.

A2Z Tools Regex Tester
https://a2z.tools/regex-tester

Preview