Guide

Regex Groups and Captures

How capturing and non-capturing groups work in a regular expression.

Groups let one pattern match several parts at once and read them back. Capturing groups change the match result; non-capturing groups only group.

01Steps

  • Wrap the part you want to read back in parentheses.
  • Use (?: ) when you only need to group, not capture.
  • Read named groups by name instead of by index.
  • Check the full match and each group separately.

02Limitations

Covers ECMAScript group syntax; other engines differ and may not support every construct.

Sources

  1. MDN: Groups and backreferences — MDN Web Docs (accessed 2026-09-01)