From the course: Learning Regular Expressions
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Solution: Backreferences - Regular Expressions Tutorial
From the course: Learning Regular Expressions
Solution: Backreferences
(upbeat music) - [Instructor] I hope you did well with the challenge assignment. If not, don't worry. I'll show you the solution that I came up with. So I'm going to do this inside the browser window instead of inside the text editor. So I'm going to just copy all of this. I'm going to paste it in as my text, so that I have the list in here. And then I'm going to start trying to write a regular expression. Remember my advice, first get a working regex, then add the captures, then write the replacement string. So let's write that basic regex that'll match these lines. So I want to match everything from the start to the end of the line. So I'll have anchors for that. And then I know that the first thing on the lines that I care about is going to be a digit, and there may be more than one, because there are more than nine presidents. And then it'll be a comma, and then after that will be the…
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.