liveBook · Manning

Regex grouping

Also called capture group, capturing group, regular expression group

A regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference.

How 7 Manning books explain it

The Well-Grounded Rubyist, Fourth Edition

A submatch is the substring matched by a parenthesized subpattern within a regular-expression match.

How it is used
Isolates useful substrings within regular-expression matches for field extraction and string substitution.
How deep it goes
Works through numbering, nested and named groups, optional captures, non-capturing groups, and retrieval through MatchData.
Examples
Uses comma-separated personal fields, a phone number, nested groups, scanned names, and a corrected letter transposition.
What you can do after
Applies it via Ruby’s match, scan, sub, and gsub to extract fields and reuse captures in replacements.

Read how The Well-Grounded Rubyist, Fourth Edition explains regex grouping →

Secrets of the JavaScript Ninja, Third Edition

A capturing group is a parenthesized regular-expression subpattern whose matched text is stored for later extraction or reference.

How it is used
Extracts parts of matched strings and lets later pattern terms require previously matched text.
How deep it goes
Explains capture indexing, nesting, optional and noncapturing groups, plus local-versus-global extraction behavior.
Examples
Uses time extraction, optional name-and-clan parsing, global roster matching, and repeated-word detection.
What you can do after
Apply it via JavaScript String.match and String.matchAll to extract captures, and use backreferences to recognize repeated text.

Read how Secrets of the JavaScript Ninja, Third Edition explains regex grouping →

Secrets of the JavaScript Ninja, Second Edition

A regular-expression subgroup whose matched text is recorded for later access or reference.

How it is used
Extracts matched substrings for later access, backreferences, and replacement logic.
How deep it goes
Works through capture positions and the different results of local match, global match, and repeated exec calls.
Examples
Uses CSS translateY extraction, HTML-tag matches, and dashed-string camel casing.
What you can do after
Apply captures via String.match, RegExp.exec, or String.replace to extract or transform matched text.

Read how Secrets of the JavaScript Ninja, Second Edition explains regex grouping →

Tiny Python Projects: Learn coding and testing with puzzles and games

A capture group is a parenthesized subpattern in a regular expression whose matched text is retained for later retrieval.

How it is used
Uses parentheses to retain matched substrings for word transformation, text splitting, and later retrieval.
How deep it goes
Explains group retrieval, numbering, optionality, nesting, and non-capturing syntax through runnable examples.
Examples
Demonstrates consonant-vowel word parsing, capitalization-preserving transformations, captured separators, and optional nested patterns.
What you can do after
Apply it via Python's re module to extract, reuse, or preserve selected portions of matched text.

Read how Tiny Python Projects: Learn coding and testing with puzzles and games explains regex grouping →

The Quick Python Book, Fourth Edition

A capturing group is a parenthesized regular-expression subpattern whose matched text is retained for later retrieval.

How it is used
Uses grouping to constrain alternatives, make portions optional, and extract fields from matched records.
How deep it goes
Explains grouped alternatives, optional and nested groups, named captures, and retrieval, while deferring a complete account of regex special characters.
Examples
Demonstrates capitalization alternatives and extracts names and phone numbers from records with optional middle names and area codes.
What you can do after
Apply grouping via Python’s re module to match optional record fields and retrieve named captures.

Read how The Quick Python Book, Fourth Edition explains regex grouping →

Modern C, Third Edition

A capture is a lambda specification identifying variables from the surrounding scope that are made available inside the lambda.

How it is used
Uses lambda captures to make surrounding expressions available inside a lambda used to implement macros.
How deep it goes
Defines init-capture syntax and its inferred, const-qualified semantics, but leaves writable captures beyond scope.
Examples
Uses pointer init-captures in a `SWAP` macro to bring its operands into a lambda.
What you can do after
Understand how init-captures make surrounding expressions available inside a lambda.

Read how Modern C, Third Edition explains regex grouping →

Python How-To

A capturing group is a delimited subexpression in a regular expression whose matched substring is retained for later access.

How it is used
Extracts individual fields from matched text for further processing.
How deep it goes
Explains parentheses, group numbering, and retrieval; flags numbering risks but does not detail named-group mechanics.
Examples
Uses a comma-separated phrase and task records with ID, title, and description fields.
What you can do after
Apply Python regular-expression matching to extract separate fields from text.

Read how Python How-To explains regex grouping →

Also covered in

What to know first

Related concepts

Questions about regex grouping

What is regex grouping?

A regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference.

Which Manning books explain regex grouping?

The Well-Grounded Rubyist, Fourth Edition, Secrets of the JavaScript Ninja, Third Edition, Secrets of the JavaScript Ninja, Second Edition, Tiny Python Projects: Learn coding and testing with puzzles and games, The Quick Python Book, Fourth Edition, Modern C, Third Edition and Python How-To.

What should I know before learning regex grouping?

Manning books that teach regex grouping usually introduce regular expression, string, Map and cucumber expression first.

What is the difference between regex grouping and non-capturing group?

A regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference. A non-capturing group is a parenthesized regular-expression subpattern that groups matching behavior without storing matched text as a capture.

What kinds of regex grouping are there?

Kinds of regex grouping include named group.

What is regex grouping part of?

Regex grouping is part of regular expression. A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.