Skip to main content

Regular expression tester

Evaluate a regular expression against text, adjust its flags, and inspect the matches to refine your pattern more easily.

  • Clipboard
  • Export

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Pattern

Was this tool useful?

How does this tool work?

Test a JavaScript regular expression against text and inspect full matches with their starting positions. Pattern and flags are entered separately to distinguish expression syntax from a code literal. Evaluation stays in your browser inside a separate Worker, with a two-second budget and a 10,000-match limit. Expensive searches can therefore be stopped without blocking the main interface.

The pattern is passed to the browser’s RegExp constructor. Enter \d+ directly, without /.../ literal delimiters or doubled string-literal escaping. Flags such as i, m, s and u follow JavaScript support in your browser. Unknown, repeated or incompatible flags produce an error.

The tester collects matches globally and adds g when omitted. The y flag still means sticky matching at the current position rather than unrestricted searching. Results contain full matches; capture groups are not displayed separately in this interface.

Each output line contains a result number, matched text and a bracketed starting index. Indices begin at zero and count JavaScript UTF-16 units. With u, an emoji may be one match while occupying two units in string indices. Positions therefore do not universally count visual characters.

The Worker is terminated when the two-second budget expires. Startup is included, so a timeout alone does not prove invalid syntax. Output is capped at 10,000 matches with an explicit truncation notice. Editing text, pattern or flags invalidates previous output; resetting stops the current task.

How to use this tool

  1. Enter a pattern without delimiters

    Put the expression in its field and flag letters separately. Source text belongs in the larger test field rather than the pattern.

  2. Test representative text

    Start small and inspect values and indices. On timeout, simplify alternatives or quantifiers before retrying reduced input.

  3. Reuse the observations

    Copy or download match text and write tests in the eventual execution environment. The exported file is not a replacement program.

Use cases

Check extraction before integration

Try representative lines and inspect starting positions. Testing does not perform replacement or register a rule in your project.

Compare search flags

Observe i for case handling or m for line anchors. Do not assume the same behavior in PCRE or SQL engines.

Reproduce Unicode indexing issues

Use supplementary characters to distinguish matched text from JavaScript indices when selecting substrings in code.

Examples

Find two occurrences with their indices

Ada with g matches both words. The first starts at 0 and the second at 8 in Ada and Ada.

Input

{
  "pattern": "Ada",
  "flags": "g",
  "text": "Ada and Ada"
}

Result

1. Ada [0]
2. Ada [8]

Separate Unicode matching from UTF-16 indexing

With . and gu, 😀 is one complete match starting at 1. B starts at 3 because the emoji occupies two UTF-16 units.

Input

{
  "pattern": ".",
  "flags": "gu",
  "text": "A😀B"
}

Result

1. A [0]
2. 😀 [1]
3. B [3]

Tips and best practices

  • Keep no-match cases: they often reveal expensive backtracking.
  • Displayed matches do not automatically overlap. Use an appropriate construction for overlapping starting points.
  • An expression matching one example is not complete email, URL or business-format validation.
  • Extracted output can contain sensitive data; review it before sharing.

Sources and references

Frequently asked questions

Should I paste /mypattern/g in the pattern field?

No. Enter mypattern as the expression and g as flags. Slashes are not automatically removed as JavaScript literal delimiters.

Why are there multiple results without g?

The tester adds g to collect occurrences. It displays a list rather than reproducing one non-global exec call.

Are capture groups exported?

Output contains full matched text and starting indices. Capture groups and their names are not separately exposed in this version.

Why was my search interrupted?

It exceeded the two-second budget. Some quantifier combinations cause extensive backtracking. Reduce input and simplify the pattern; stopping the Worker keeps the interface usable.

Does this reproduce PCRE or Python?

No. Syntax and flags come from JavaScript RegExp in your browser. Other engines may differ in supported constructs, indices and Unicode behavior.

Related tools

Tools similar or complementary to this one.

Similar tools

Replace a text fragment in a pasted or imported document.

DevelopmentNewUse this tool

Format JavaScript, TypeScript or JSX for easier reading without executing code. Processing runs locally in your browser.

DevelopmentUse this tool

Query JSON data with a simple JSONPath expression.

DevelopmentUse this tool