Included in at least one reviewed higher-education syllabus.
2.4 Strings, formatting and regex
You can clean messy text without a library.
Before:00. Orientation & SetupUnlocks:03. Data Handling & Analysis04. Classical AI — Agents, Search & Knowledge Representation
Text cleaning is a daily chore of data work, and this topic equips it: f-strings for output, regex for extraction, and the bytes-versus-str split that explains encoding errors which only appear on someone else's machine. It sits in the foundation run because messy text arrives before models do. The regex caution is worth keeping: greedy quantifiers and unanchored patterns match more than intended, and an over-clever pattern is a bug that looks like a solution.
Work through these
f-strings and format specs
Formatted string literals put values directly into text with control over how they appear. They are the current standard way to build strings and worth adopting immediately.
Encoding, Unicode and the bytes/str split
Text and raw bytes are different types for a reason, and the boundary between them is where encoding errors happen. Understanding this saves hours when reading files from unfamiliar sources.
Regex: groups, quantifiers, anchors, lookahead
Regular expressions describe patterns in text, with syntax for grouping, repetition, position and conditions. They are dense to read and enormously useful in cleaning.
re module: search, findall, sub
The standard library functions for finding a pattern, collecting every match, and replacing. Between them they cover most practical text repair.
Sign in to keep your progress.
Free resources
We haven't checked most of these for screen reader use yet.
Links last checked 29 Aug 2026.
Stuck here?
Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.
Checking your session…
Topics shown in module order.