In this video, you learn how to extract text that contains numbers for this example, we'll work on
this.
I piece the text file that I have in here and you can find this untouched in the lecture resources.
So we have IP addresses in this text file.
Our purpose is to extract only those IP addresses that start with 12 in the third part of the IP address.
So that's the first, both the second and the third part.
This starts with the 12th.
The first one also starts with 12.
So we want this and that's let's build the codes for that.
With open eyepiece that you see in reading modes as file, we load the contents in a content variable
using file that reads.
So that is the contents in a variable now.
We built the pattern, which is our readers compile with numbers now.
We use a number range.
So we want the first part, which could be any number.
That means you want to use square brackets and use a number range.
So we have digits from zero to nine.
Right.
And we want to match three times of three digits.
That means we could have one digits from zero to nine two digits three digits maximum.
Don't try to match more than that's because after that, we want to match a dots.
So backslash dot actually, because adults is a special character, so we need two escapees with backslash.
Then we have more ranges from zero to nine.
Again, three times because every part of the IP address has three numbers.
Again, backslash dot, we only want 12.
So this time this would be a literal character.
It's a one and two.
Then after that, we could have any number.
So again, the third number of this third part of the IP address could be anything from zero to nine.
And we want to match it.
Three.
Sorry, one time only.
So there's only one number after that.
Then we have backslash dot and then the last parts could be again, anything so zero, two nine, three
times.
That's it.
Matches are equal to pattern dot finds all content.
And let's call them here, executes.
And this is the output, so it's a list of two items and we have this item, which starts with 12 in
the third part and the other IP address again, starting with 12.
So simple and clear, that's how you would work with numeric texts such as IP addresses.
I'll talk to you in the next video with some more examples.