From the course: Python in Excel: Getting Started with Data Analysis

Unlock the full course today

Join today to access over 24,600 courses taught by industry experts.

Extract data with regular expressions

Extract data with regular expressions

- [Instructor] This example really demonstrates the power that Python brings to the Excel environment. Anyone who's ever worked with data has probably encountered a situation where the information is not exactly in the perfect form where you can easily process it. So for this example, I have a set of strings that can contain North American phone numbers. And you can imagine this data came from any one of a number of sources, right? Some freeform input field or something like that. And what I want to do is extract the phone number from each string and then format it in a specific, consistent way. But there's two problems. First, you can see that the phone numbers are embedded inside random text strings, right? It's not just the regular phone number by itself. There's a text string, and the phone number is somewhere within it, either at the beginning or the end, or somewhere in the middle. And second, you can also see the phone numbers don't follow a predictable format. So this one here…

Contents