A regex describes a SHAPE — digits, letters, repeats — and the re module hunts down every spot in a string that fits.
1 Patterns, Not Words
A regex is a rule for text: find me digits, find me words, find me any character here.
2 findall = All Hits
re.findall returns every match as a list; an empty list means nothing matched.
3 search = First Hit
re.search gives a match object with .group() and .start() — or None.
4 Tiny Symbols
\d digits, \w word characters, . any character — small glyphs, big power.
Patterns, not just words
Patterns, Not Words1A regex is a rule for text: find me digits, find me words, find me any character here. findall = All Hits2re.findall returns every match as a list; an empty list means nothing matched. search = First Hit3re.search gives a match object with .group() and .start() — or None. Tiny Symbols4\d digits, \w word characters, . any character — small glyphs, big power. 4 building blocks make up Patterns, not just words
findall collects every hit, search reports the first with its exact position.
mainre is the pattern-matching module — its tools hunt text by rules, not just fixed words.
Memory
no variables yet — press play
Console
output appears as the program runs…
The engine slides through the text one index at a time, collecting everything that fits.
process decision input / output start / end Click a term, then click its description to lock the pair.
6 conceptsTap a card to expand ?re.findall(p, s)drops into place
?re.search(p, s)drops into place
?\ddrops into place
?\d+drops into place
?.drops into place
?\wdrops into place
Digits on demand, plus one wildcard pattern hiding in the rooms.
Your predicted output — one line per console line
Hint: r"\d+" grabs runs of digits. The dot in "o.m" is a wildcard for any single character — so it finds "oom" three times.
01import re; re.findall(pattern, text) returns a list of all matches.
02re.search(pattern, text) returns a match object — use .group() and .start(), or check for None.
03\d means one digit; adding + means one or more in a row.
04The dot . is a wildcard for any single character — mix it with \w and \d freely.
05No match? findall gives [] and search gives None — never an exception.