GUIDE深度 · Deep dive
Groups, Greediness and Lookaround
Parentheses capture; use (?:...) to group without capturing. Quantifiers are greedy by default; add ? for non-greedy. Lookahead (?=...) and lookbehind (?<=...) check position without consuming.
Groups
(\d+)-(\d+) captures two numbers.
(?:ab)+ groups without capturing.
Lookaround
a(?=b) matches a followed by b.
(?<=a)b matches b preceded by a.
When a pattern gets complex, name the groups or split it into smaller expressions so you can test each piece separately.
FAQ
Greedy vs non-greedy?
Greedy takes as much as possible; non-greedy as little.
Does lookaround consume?
No; it only checks position.