Groups and CapturingLesson 2.3
Non-capturing groups and grouping without capturing
non-capturing group syntax, performance difference, grouping for quantifiers, alternation scope, when to use
Group Without the Overhead of Capturing
Every capturing group allocates a slot in the match result. If you only need grouping for quantifier or alternation scope — not extraction — use a non-capturing group: (?:pattern).
// Group for quantifier, no capture needed
/(?:ab)+/.test('ababab') // true — matches 'ab' repeated
// Alternation scope
/^(?:cat|dog)s?$/.test('cats') // true
Non-capturing groups are also faster in engines that optimize capture tracking.
