Regular Expressions

Lesson 18 of 20

Hunt text by pattern instead of by word: findall, search and the tiny symbols that match digits and wildcards.

The big picture

Patterns, not just words

A regex describes a SHAPE — digits, letters, repeats — and the re module hunts down every spot in a string that fits.

Patterns, Not Words

A regex is a rule for text: find me digits, find me words, find me any character here.

findall = All Hits

re.findall returns every match as a list; an empty list means nothing matched.

search = First Hit

re.search gives a match object with .group() and .start() — or None.

Tiny Symbols

\d digits, \w word characters, . any character — small glyphs, big power.