Tool

Regex Tester

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

Try it

This tool runs entirely in your browser. Nothing you type or paste is sent anywhere.

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": []
  }
]

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

How it works

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

All digits

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

Capture groups

{
  "pattern": "(\\w+)@(\\w+)\\.com",
  "subject": "[email protected]"
}

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