DevTools Logo

Regex Explainer

Regex Explainer

Turn a cryptic regular expression into a plain-English, token-by-token breakdown with a live match preview.

Pattern

Test text

Examples

Find dates and expose capture groups

Input
/\d{4}-\d{2}/g
text: 2026-07 and 2025-01
Output
{
  "matches": [
    {
      "match": "2026-07",
      "index": 0,
      "groups": [
        "2026",
        "07"
      ]
    },
    {
      "match": "2025-01",
      "index": 12,
      "groups": [
        "2025",
        "01"
      ]
    }
  ],
  "error": null
}

The live matcher reports both global matches, their zero-based indexes and the two numbered capture groups from the date pattern.

Use a character class for country codes

Input
[A-Z]{2}
text: US uk GB
Output
{
  "matches": [
    {
      "match": "US",
      "index": 0,
      "groups": []
    },
    {
      "match": "GB",
      "index": 6,
      "groups": []
    }
  ],
  "error": null
}

The uppercase range matches US and GB but not the lowercase uk in the same test string.

Capture a key and numeric value

Input
(?<name>[A-Za-z]+)=(\d+)
text: port=3000 host=1
Output
{
  "matches": [
    {
      "match": "port=3000",
      "index": 0,
      "groups": [
        "port",
        "3000"
      ]
    },
    {
      "match": "host=1",
      "index": 10,
      "groups": [
        "host",
        "1"
      ]
    }
  ],
  "error": null
}

The named group is reported in the same ordered groups array as the numeric group, so the result is easy to compare with JavaScript match output.

About this tool

Reading a dense regular expression is often harder than writing one — a pattern like ^(?<year>\d{4})-(\d{2})-(\d{2})$ hides its meaning behind terse metacharacters. This explainer walks the pattern token by token and describes each piece in plain English, so you can understand exactly what a regex matches without running it in your head.

It parses anchors, character classes and their ranges, shorthand classes like \d and \w, capturing/non-capturing/named groups, lookahead and lookbehind assertions, alternation, and quantifiers including lazy variants. Alongside the explanation, a live match preview runs your pattern against sample text and highlights every match and capture group, and a library of common patterns (email, URL, IPv4, hex colour, ISO date, slug and more) gives you a vetted starting point. Everything is parsed and matched locally with the browser's own RegExp engine.

How to use this tool

  1. Paste a pattern

    Enter a regular expression, with or without the surrounding slashes and flags.

  2. Read the breakdown

    Each token is listed with a plain-English description of what it matches.

  3. Test against sample text

    Type test text to see every match highlighted and the first match's capture groups.

  4. Start from a common pattern

    Insert a vetted pattern from the library, read its explanation, then adapt it.

Use cases

Explaining a production regex during review

Paste a pattern from validation or log parsing code and use the token-by-token descriptions to make anchors, groups and quantifiers explicit for the team.

Debugging a capture-group mismatch

Run the pattern against a small test string and inspect the first match's group values and indexes before changing the expression.

Learning a regex construct

Start with a common email, URL, IPv4, ISO date or slug pattern, then read the breakdown before adapting it to your own input.

Checking a pattern against multiple inputs

Use the live preview to see every global match highlighted and quickly spot an anchor, case or character-class assumption that is too broad.

What it explains

ConstructExample
Anchors^ start, $ end, \b word boundary
Shorthand classes\d digit, \w word char, \s whitespace
Character classes[a-z0-9], [^abc] (negated)
Groups(...), (?:...), (?<name>...)
Assertions(?=...), (?!...), (?<=...), (?<!...)
Quantifiers*, +, ?, {n,m}, and lazy variants (*?)

Parsing and matching run in your browser via the native RegExp engine.

Common mistakes

Mistake:Assuming a pattern without g will show only one match.

Fix:The tool adds g internally when running the live preview, so it reports all matches even when the entered pattern has no global flag.

Mistake:Reading a slash-wrapped pattern as literal slashes.

Fix:The explainer recognizes /pattern/ followed by the supported flags g, i, m, s, u and y, then explains the body separately.

Mistake:Expecting the explanation to validate business rules.

Fix:The parser describes native JavaScript regex constructs; test semantic requirements such as valid dates, ranges or normalized identifiers separately.

Mistake:Forgetting that dot does not match a newline by default.

Fix:Use the s flag when the intended pattern should let . cross line breaks, and verify the live preview with a multi-line test string.

Frequently asked questions

Which regex constructs are explained?

It describes anchors, character classes and ranges, shorthand classes, groups, lookarounds, alternation and greedy or lazy quantifiers.

Does it show matches as well as token descriptions?

Yes. A live preview runs the pattern against sample text, highlights matches and exposes capture groups.

Can I start from a known pattern?

Yes. The pattern library includes examples such as email, URL, IPv4, hex color, ISO date and slug expressions.

References & standards