Source: https://mokxi.com/teachers/plans/text-processing-regex
Updated: 2026-11-19

Lesson plan

# Text and regular expressions lesson plan

Strings, split and join, then regular expressions from search to named groups, on a rocket launch log and a ship's GPS feed, ending in a log analyzer on a Raspberry Pi.

4 chapters, 7 lessons, about 5 hours, on the Raspberry Pi 4 Model B. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- What a string really holds, and how to cut a line into fields.
- Describe text instead of spelling it out, and pull out the pieces.
- A launch log and a ship's GPS, turned from text into data.
- A log analyzer that answers commands and lights an alarm.

### Materials for the whole unit

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 20 min

## Text, cut and glued

What a string really holds, and how to cut a line into fields.

Lesson | Time | What students do

Strings deep One line of a rocket launch log, taken apart: repr and strip, indexing and slicing, find, in and count, why strings never change, format specs for tidy tables, and escape characters and raw strings. | 40 min

- Run it: what is really in a string
- Index and slice
- Search inside a string
- Strings never change
- Tidy columns with format specs
- Escapes and raw strings

Split and join split() on a separator, on whitespace and with a limit, unpacking fields into names, reading a whole log file line by line, join() to glue text back together, and partition() for key=value telemetry. | 40 min

- Run it: split a line into fields
- Unpack into names
- Three ways to split
- Read the whole log
- Glue it back with join
- partition for key=value

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Split and join" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "partition for key=value".

Chapter 2. About 1 h 20 min

## Regular expressions

Describe text instead of spelling it out, and pull out the pieces.

Lesson | Time | What students do

re basics Regular expressions with re: search and the Match object, character classes and repeats, anchors and MULTILINE, counted repeats and word boundaries, re.split and re.sub, and compiled patterns with flags. | 40 min

- Run it: search for a pattern
- Character classes and repeats
- Anchors and MULTILINE
- Exact counts and word edges
- Split and replace with patterns
- Compile once, with flags

Groups Brackets that capture: group() and groups(), turning a T-minus stamp into seconds, named groups and groupdict, findall with groups and non-capturing groups, back-references in re.sub, and finditer with positions. | 40 min

- Run it: brackets capture
- Turn a stamp into seconds
- Named groups
- findall with groups
- Back-references in re.sub
- Every match, with positions

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Groups" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Every match, with positions".

Chapter 3. About 1 h 20 min

## Parsing real feeds

A launch log and a ship's GPS, turned from text into data.

Lesson | Time | What students do

Parsing logs A parser for the whole launch log: one regex per line into (time, system, message) records, telling comments from garbage, counting by system, formatting stamps back, timing events by pattern, and pulling a time window. | 40 min

- Run it: a line in, a record out
- Comments are not errors
- Count by system
- Stamps back out
- Time between events
- A time window

Parsing NMEA lines A ship's GPS feed in NMEA 0183: the XOR checksum that catches corrupted sentences, GGA fields by position, degrees and minutes to decimal degrees, a regex that validates and sorts sentence types, and speed and course from RMC. | 40 min

- Run it: the ship talks
- Check the checksum
- GGA fields by position
- Degrees and minutes to decimal
- Validate with one pattern
- Speed and course

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Parsing NMEA lines" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Speed and course".

Chapter 4. About 50 min

## Project

A log analyzer that answers commands and lights an alarm.

Lesson | Time | What students do

Project: a log analyzer Everything in one tool: load and parse the launch log, then answer typed commands (grep with any regex, a time window, ranked stats), survive a broken pattern, and light a red alarm LED when the log holds warnings. | 50 min

- Run it: load the log
- A command prompt with grep
- Survive a broken pattern
- A time window command
- Light the alarm
- Ranked stats
- Make it yours

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Project: a log analyzer" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
