GUIDEDeep 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.
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 guideKEEP READING
Keep reading
Read in order, or jump to another guide on the same topic.
← PreviousRegex Basics: Classes, Quantifiers, Anchors\d, \w, +, *, ?, ^, $ and escaping.Next →Tenses and Subject-Verb AgreementPresent/past, perfect tenses and third-person singular.
同主题Articles, Prepositions and Passive Voicea/an/the, collocations and was/were + past participle.同主题Learning English, French and Spanish TogetherMain language, maintenance language and cognate strategy.同主题Cognates and False FriendsSimilar-looking words in English, French and Spanish: when to guess and when…