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.

更新 2026-10-30 · 公式可核验

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.

Sources

Related calculators

Regex Practice: 1000 Gamified Match and Replace Cards1000 Python regex cards covering character classes, quantifiers, groups, anchors, search and substitution, in 50 levels with spaced repetition.

More guides

Hiragana vs KatakanaRead guideSpaced Repetition and the Forgetting CurveRead guideOn Readings vs Kun ReadingsRead guideAn N5 Kanji Study OrderRead guide