Non-capturing group
A non-capturing group is a parenthesized regular-expression subpattern that groups matching behavior without storing matched text as a capture.
Secrets of the JavaScript Ninja, Third Edition
A non-capturing group is a parenthesized regular-expression subpattern that groups terms without storing its matched text as a capture.
- How it is used
- Groups regex terms without adding the group’s matched text to the match array.
- How deep it goes
- Explains `?:` syntax, nested captures, optional groups, and repeated-group behavior without detailing regex-engine internals.
- Examples
- Uses an optional ninja clan name and a repeated word-and-whitespace pattern to demonstrate non-capturing groups.
- What you can do after
- Understand how to group regex terms without adding an unwanted capture to the match array.
Read how Secrets of the JavaScript Ninja, Third Edition explains non-capturing group →
Regular Expression Puzzles and AI Coding Assistants
A non-capturing group is a parenthesized regular-expression group whose matched text is not stored as a numbered capture.
- How it is used
- Frames non-capturing groups as a diagnostic detail when evaluating plausible-looking but unreliable regular expressions.
- How deep it goes
- Defines the syntax and examines it inside failed patterns, stopping short of a general regex tutorial.
- Examples
- Uses @-encoded prime and Fibonacci claims plus a FASTA telomere-matching program with incorrect output.
- What you can do after
- Evaluate/understand whether a regex explanation distinguishes grouping from capturing and whether its overall claim follows.
Read how Regular Expression Puzzles and AI Coding Assistants explains non-capturing group →
The Well-Grounded Rubyist, Fourth Edition
A non-capturing group groups a regular-expression subexpression for matching without storing its text as a numbered capture.
- How it is used
- Uses grouping to match a subexpression while keeping numbered captures focused on text the program needs to retrieve.
- How deep it goes
- Explains syntax, character consumption, and MatchData capture numbering, contrasting groups with zero-width assertions.
- Examples
- Demonstrates /(abc) (?:def) (ghi)/ and its two numbered captures in Ruby MatchData.
- What you can do after
- Apply it in Ruby regular expressions to group matching logic without shifting or storing an unwanted numbered capture.
Read how The Well-Grounded Rubyist, Fourth Edition explains non-capturing group →
Secrets of the JavaScript Ninja, Second Edition
A regular-expression group that combines subpatterns without recording their matched text as a capture.
- How it is used
- Uses noncapturing groups to group regex subpatterns without collecting unwanted captures, including in newline-matching alternation.
- How deep it goes
- Defines `(?:...)`, demonstrates its effect on captures, and notes readability and performance trade-offs without detailing engine internals.
- Examples
- Demonstrates repeated `ninja-` prefixes before `sword` and alternation that matches newline-containing HTML.
- What you can do after
- Build it from scratch by grouping repeated or alternative pattern text with `(?:...)` while preserving intended captures.
Read how Secrets of the JavaScript Ninja, Second Edition explains non-capturing group →
Also covered in
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.
Related concepts
- regex groupingcontrasts with · A regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference.
- regular expressionused by · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- assertioncontrasts with · A regular-expression assertion tests a condition at a position in the input without consuming characters as part of the match.
- negative lookahead assertionalternative to · A negative lookahead assertion is a regular-expression assertion that succeeds when its pattern does not match immediately after the current position without consuming characters.
- ChatGPTused by · ChatGPT is OpenAI’s conversational AI service, which lets users interact with generative AI models and related tools through natural-language prompts.
Questions about non-capturing group
What is non-capturing group?
A non-capturing group is a parenthesized regular-expression subpattern that groups matching behavior without storing matched text as a capture.
Which Manning books explain non-capturing group?
Secrets of the JavaScript Ninja, Third Edition, Regular Expression Puzzles and AI Coding Assistants, The Well-Grounded Rubyist, Fourth Edition and Secrets of the JavaScript Ninja, Second Edition.
What should I know before learning non-capturing group?
Manning books that teach non-capturing group usually introduce regular expression first.
What is the difference between non-capturing group and regex grouping?
A non-capturing group is a parenthesized regular-expression subpattern that groups matching behavior without storing matched text as a capture. A regex capturing group is a parenthesized regular-expression subpattern whose matched text is retained for separate access or reference.
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.



