From the course: Programming Foundations: Beyond the Fundamentals
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Creating regular expressions - Python Tutorial
From the course: Programming Foundations: Beyond the Fundamentals
Creating regular expressions
- Sometimes working with patterns requires more complicated searching in order to do the manipulation you need. Say I want to find every instance in this pattern where a yellow brick is followed by one or more red bricks and replace that whole sequence with a single blue brick. I don't want to replace just the yellow bricks, and replacing each yellow followed by one red might still leave some red bricks that I want to replace. So my process has to be really detailed and meticulous. Strings sometimes need complex searches and manipulations, too. Many programming languages, including Python, allow you to do this by supporting regular expressions. A regular expression lets you create a description of a pattern that you want to match. You can then check a string against the regular expression, and if it matches, you can use one or more methods to work with the results. A regular expression is also known as a Regex, or reg-ex,…
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.