Regex Tester

Test a regular expression against a subject and inspect matches and capture groups.

  • Runs locally in your browser
  • No upload required

Try it

Any of g, i, m, s, u, y — each at most once.

Matches
3
Match 1 index
1
Match 1 length
1
Match 1 value
1
Match 2 index
3
Match 2 length
2
Match 2 value
22
Match 3 index
6
Match 3 length
3
Match 3 value
333
[
  {
    "index": 1,
    "length": 1,
    "value": "1",
    "groups": []
  },
  {
    "index": 3,
    "length": 2,
    "value": "22",
    "groups": []
  },
  {
    "index": 6,
    "length": 3,
    "value": "333",
    "groups": []
  }
]

Supported formats

Input
text, regex
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Found 3 match(es) for /\d+/g.

How it works

  • Compiled a fresh regular expression from the pattern and flags.
  • Advanced through the subject collecting every global match.
  • Recorded each match's start index, length, value, and capture groups.
  • A fresh RegExp is compiled on every call, so lastIndex never leaks between tests.

Methodology

  1. Compile a fresh ECMAScript RegExp from the pattern and flags, then run it against the subject.
  2. Advance through the subject collecting every global match, or test once for a single match.
  3. Record each match's start index, length, value, and capture groups without exposing a stack trace as a result.

Usage

  1. Enter a regular expression pattern.
  2. Optionally add flags such as g, i, or m.
  3. Paste the subject text and read the matches and groups.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

All digits

jsonSelect to copy
{
  "pattern": "\\d+",
  "flags": "g",
  "subject": "a1b22c333"
}

Capture groups

jsonSelect to copy
{
  "pattern": "(\\w+)@(\\w+)\\.com",
  "subject": "ada@example.com"
}

Limitations

Global state and lastIndex

A RegExp with the g or y flag stores its position in lastIndex. Reusing one object between tests is a classic source of 'every other match is skipped' bugs. This tool compiles a new RegExp for each call, so results are reproducible.

Frequently asked questions

Which flags are supported?
The JavaScript flags g, i, m, s, u, and y, each at most once.

Sources

  1. ECMAScript Language Specification, RegExp Objects — TC39