Regex grouping
A regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference.
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.
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.
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.
Also covered in
- Learn AI Data EngineeringIn early access (MEAP)
- Julia as a Second Language
- BDD in Action, Second Edition
- Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu
- Regular Expression Puzzles and AI Coding Assistants
What to know first
- regular expressionA regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- stringA string is a programming-language value representing textual data as an ordered sequence of characters or encoded units.
- MapA map is an associative data structure that stores key-value associations and supports retrieving values by key.
- cucumber expressionA Cucumber expression is a pattern syntax for matching step text and converting parameter placeholders into values for step definitions.
Related concepts
- non-capturing groupcontrasts with · A non-capturing group is a parenthesized regular-expression subpattern that groups matching behavior without storing matched text as a capture.
- regular expressionpart of · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- backreferenceused by · A backreference is regular-expression or replacement-string notation that refers to text captured by a capturing group.
- conditional matchused by · A conditional match selects between regular-expression subexpressions according to whether a specified capture was found.
- exec methodproduced by · The JavaScript RegExp exec method searches a string for a match and returns a match result with captures or null if no match is found.
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.






