Save this video free

Lecture 23: Regex 2

Professor Rosen · 57:28 · Watch on YouTube

Part of Temple University CIS 1051. See all 23 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

The lecture explains Python regular-expression syntax and practical use, including raw strings, greedy non-overlapping matches, character classes, quantifiers, alternation, and `re.findall` and `re.sub`. A file-redaction exercise builds a pattern for InsureCare IDs, which contain 2 to 3 uppercase letters and a dash followed by 12 digits, either contiguous or in three four-digit groups separated by dashes; the lecture also covers reading and writing files and introduces a regex extra-credit assignment.

Key takeaways

Chapters

0:00 Regular Expressions Across Java, Go, and Python
3:40 Python Raw Strings Prevent Backslash Escaping Conflicts
6:05 Python Regex Functions and Greedy, Non-Overlapping Matches
10:45 Why Regex Simplifies the Phone-Number Example
13:15 Exam Search Tricks and the InsureCare Redaction Exercise
15:45 InsureCare ID Rules and the Need for Precise Matching
23:45 Regex Alternation and Character Classes for ID Formats
30:05 Build the ID Pattern with Quantifiers and Grouped Alternatives
38:35 Read the Input File and Verify Matches with `re.findall`
43:00 Redact Matches, Write the Output File, and Check It in a Terminal
51:00 Regex Extra Credit with a 45,000-Word Dictionary

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:03 All right. So, Sorry, don't mean to cut you off, but I need to get started with the lecture. So, we are going to continue with our discussion of regular expressions, right? To remind you, we have this we we we stopped off by talking about the fact that we have these regular expressions and we have these libraries in every different language. For instance, regex in Java, right? Here's school for Here it is for Java 8, right? Regex in Let's go with something fun, Go in Go Lang, right? Which is Google's programming language Go or one of their programming languages that that they did, right? Package regex implements regular expression search,

0:51 right? With Python Sorry, with Java, right? They have this entire thing on how to use these patterns, which is part of the regex field. But also, and I know we aren't learning Java right now, but let's just go ahead and like talk about just I want to show this. Java String, okay? This is just I want to emphasize why this is potentially important, right? If we go into the String class in Java, right? I can control F this page, find and look for takes in String regex. Tests whether this string matches the given regular expression. So, you can use So, strings the String library uses you know, it has a use for regex even if you don't import it, right? That's

1:39 So, that kind of gives an indication of just how baked in these things are. Um similarly, you've got our match it So, we've got our matches, we've got replace first, replace all, which is one I use plenty in String operations, which says, hey, given a regex, a pattern, let's replace all the of that. Now let's take a look in at the Python language,

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Professor Rosen.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.