Tutorial · Regex Tester · 5 min read

How to Test a Regex with Capture Groups

Test a regular expression against sample text, see every match highlighted, read capture groups, and understand the g, i and m flags with practical examples.

Regular expressions fail quietly: no match, or the wrong match. A tester shows every match highlighted in context and lists each capture group, so you can see exactly what the pattern grabbed before it goes into production code or a log filter.

What you'll learn

  • Write a pattern and see matches highlighted as you type
  • Extract parts of a match with capture groups
  • Choose flags: g for all matches, i for case-insensitive, m for per-line anchors

Step by step

  1. Enter the pattern and flags

    Open the Regex Tester. Type the expression without slashes and put flags in the small box: i, m, s, u or y. The tester always searches the whole text, so every match is listed whether or not g is set.

  2. Paste sample text

    Use real data: a log excerpt, a list of emails, a config file. Matches highlight instantly.

  3. Read the groups

    Each match is listed with its index and its capture groups in order. Group 1 is the first pair of parentheses.

    Pattern: (\d{4})-(\d{2})-(\d{2})
    Text:    Deployed 2026-09-10 at 10:12
    
    1 match
    #1 "2026-09-10" — group 1: "2026" · group 2: "09" · group 3: "10" at index 9
  4. Refine and copy

    Adjust the pattern until only the intended text matches, then Copy Matches for a quick sanity list.

Open the tool with this example Runs in your browser. Nothing you paste is uploaded.

Common problems

The match grabs far too much

Quantifiers are greedy by default: .* runs to the last possible character. Use the lazy form .*? or a negated class such as [^,]* to stop at the first delimiter.

^ and $ do not match each line

Add the m flag. Without it the anchors apply to the whole text.

Unterminated group

A ( has no matching ). Escape literal parentheses as \( and \).

FAQ

Which regex flavour is this?

JavaScript, as implemented by your browser. It covers the syntax shared by most languages; look-behind and named groups are supported in modern browsers.