Module 4 · Lesson 1 of 413/32 in the course~16 min
Module lessons (1/4)
Capture groups: `(...)`
Lesson preview5 hands-on exercises readyRegex Course · Module 4 — Groups and alternation
Parentheses to group and capture; access groups 1, 2, 3… in matches.
What you'll learn in this lesson
- Use parentheses
(...)both to group multiple atoms under a quantifier and to extract substrings as numbered groups. - Understand the group numbering order (from left to right counting each open parenthesis
(). - Read extracted groups in JavaScript via
match[1],match[2], ... or viamatchAll. - Avoid the common
ab+mistake when the intent is to repeat the entire(ab)+pair.
Overview
The round brackets (...) perform two simultaneous tasks: they group multiple atoms so that quantifiers or alternatives operate on the entire block ((ab)+ instead of ab+), and they capture the matched substring by exposing it as a numbered group ($1, $2, $3, ...) ordered according to the open brackets from left to right.
Sections covered in this lesson
- 1Mental model: full match vs. capture groups
- 2Progressive examples
- 3Guided laboratory
- 4Check for understanding
Pro Lesson · Module 4 — Groups and alternation
Unlock "Capture groups: `(...)`" and the full Regex Course curriculum
Parentheses to group and capture; access groups 1, 2, 3… in matches.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Regex Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.