Skip to main content
Module 4 · Lesson 3 of 415/32 in the course~16 min
Module lessons (3/4)

Non-capturing groups: `(?:...)`

Lesson preview5 hands-on exercises readyRegex Course · Module 4 — Groups and alternation

Group without creating a capture: useful when you only need to quantify or alternate.

What you'll learn in this lesson

  • Distinguish between capture groups (...) and non-capture groups (?:...).
  • Use (?:...) when brackets are needed only to quantify ((?:ab)+) or isolate alternatives ((?:http|https)) without polluting the group numbers $1, $2.
  • Recognize the readability, maintenance, and memory efficiency advantages of non-capture groups.
  • Avoid any syntactic confusion between (?:...) (group that consumes characters) and (?=...) / (?!...) (zero-width lookaround).

Overview

Often you only need parentheses to group (apply a quantifier or confine a pipe |), without wanting to store that fragment in $1, $2... In all these cases use the non-capture form (?:...): group exactly like (...), but does not allocate any capture index.

Sections covered in this lesson

  1. 1Mental model: (?:...) vs (...)
  2. 2Progressive examples
  3. 3Guided laboratory
  4. 4Check for understanding
Pro Lesson · Module 4 — Groups and alternation

Unlock "Non-capturing groups: `(?:...)`" and the full Regex Course curriculum

Group without creating a capture: useful when you only need to quantify or alternate.

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.