From the course: Learning Regular Expressions
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Challenge: Backreferences - Regular Expressions Tutorial
From the course: Learning Regular Expressions
Challenge: Backreferences
(upbeat music) - [Instructor] It's time for another challenge assignment. This challenge, we'll use what we've learned about backreferences. In the exercise files, there's a file called us_presidents.csv. It's a list of the U.S. presidents and the data about each one is a set of comma-separated values. The challenge is to use captures, backreferences, and find-and-replace to create a new list in the format start-end: full name. Let me give you an example to show you what I mean. The line for John Tyler looks something like this. Between the commas, we have values for the sequence number, name, term start and end, political party, home state, and the URL for his Wikipedia entry. The challenge is to match the parts of each line that we care about, to capture them, and then use backreferences to construct a replacement string that looks like this. It has the start year, then a dash, then the end year, then a colon, and…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.