GROUPS & ALTERNATION

Non-capturing groups

Group without capturing: (?:...) bundles, but stores nothing.

Every plain group quietly captures the text it matched, ready for reuse later. Often you only want the bundling - to apply a quantifier or hold an alternation - and have no use for the capture. `(?:...)` is a group that bundles but does NOT capture: same grouping power, no stored slot.

Two reasons to reach for it. It keeps your capture numbers clean: skip the throwaway group with (?:...) and the ones you DO care about stay $1, $2 in order instead of shifting every time you wrap something. And it signals intent - a reader sees (?:...) and knows "grouping only". The next lessons lean on numbered captures, so the habit pays off fast.

Functionally (?:ab)+ and (ab)+ match the same text - this playground checks the match, not the capture slots, so both pass the drill. The difference bites the moment you start numbering groups, which is the very next lesson.

EXERCISE

Match one or more repetitions of "ab" or "cd" back to back. Bundle the alternation in a non-capturing group.

/ /
ababcd done
must match: "ababcd"
cd ab cdcd
must match: "cd" "ab" "cdcd"
xyz
must match nothing