So far in this section we took the boats were regular expressions in the first video, then in the second
video, we looked at an example of a regular expression.
This one in here, we extracted the email addresses from this text.
In this video, we will take a look at the meter characters that you can use to build regular expressions.
And I'm going to go through each of these characters and explain them using the same example.
So you are familiar with this text now.
That's a sort of text variable, and that is the codes.
So we will be changing the regular expression here, the pattern using all these metal characters.
Well, let's start with the first one.
The first one is the dot, a dot is a major character.
You can also call these special characters so metal characters.
These dot means you want to match any possible characters.
It could be a wide space, a comma, a laser lowercase or uppercase, and any other character.
Even the dots can be matched using these dots character.
So well, let's take a look at the example here.
We did use these dots, actually.
You see here what these did, in fact, is it matched any character at this position.
So we had any character, but space, that's then we had it here than we had any character again, except
space.
Then we had any character.
So one single dot means any character.
So it happens to be in our scenario that this any character was a dot.
But even if it is, for example, an equal operator, let's say, and we execute this cell again, we're
going to match both these email addresses because the DOT captures any character.
So you see that it's just so you see that it also matched this equal operator.
But in our example, we actually have dots in email addresses, and that brings us to the second major
character.
This character is used to escape one of the major characters.
So to treat it as a regular character, which means if you put that backslash before a major character,
the dots in this case, and if this first e-mail address has, that's equal operator as a character
instead of the dots and you execute this, we're only going to get to the second email address because
in this pattern, this time the dots is a literal dots.
It's a normal character because it has this escape made-up character in front.
So that's backslash comes in handy whenever you want to escape a major character.
Next, the square brackets, which could have anything inside.
So these three dots are just to denote that the square brackets come with something inside.
So this is an example of the square brackets.
That's metal character, and that's it's another example.
So inside these square brackets, we can put a single character or arrange or characters within those
brackets.
Let's see what happens if we remove this character here and the space and inside the first pair of brackets
we inputs, another executes.
We get the second email address, so another and then we have ETS and so on.
But what if we remove the brackets like that and we execute again, we get the same results?
So what is the point of having those brackets when you get the same output?
Well, when you have the brackets, you can have the characters arranged in any order.
So let's change the place of a and put it off the end.
So in a other instead of another, if you execute that, it's still going to match that string.
So the order of characters, it doesn't matter if all these characters match a string, regardless of
the order, you will have a match.
But if you remove the brackets, no.
You will not get to the scene because this is not a major character.
No, it's not inside those square brackets.
So let's put the brackets again.
Of course, if you remove an order and you execute Steve, you don't get a match because not all the
characters are matched.
That's what I'm trying to explain here that the order does not matter.
Next, the gloss metal character, we already use the glass.
It means that, you know, we had this.
It means match any known space character one or more times.
So that means this first part or the email address codes have at least one or more known space characters,
which could be letters on the scores, dashes, columns, semicolons, et cetera, but not spaces.
Next, we have a question mark.
This matches the preceding element zero, actually, it should be zero or one time.
So see what happens if we replace the plus here with a question mark and executes.
You will get only the last letter of the words another because one matches is the best.
That's this question mark and two.
So it's only catch catches one letter.
Then we have the asterisk, which matches the preceding elements zero or more times.
So the Plus got at least one or more times, which means in the case of class, which was like this.
We got another example, the.
And if we have adults here, in example dot com, we also get that.
But if we replace that to an asterisk and execute again, we get the same result.
But see if we at dot com to this, it's blah blah blah.
We will get at blog dot com.
Also, because the asterisk matches zero or more elements, which means there are zero elements before
the ETS.
So zero elements are allowed to be before the at symbol.
Therefore, we get that.
So if you don't want that, you want to use the loss to get at least one element if you want a particular
number of elements to match a particular number of characters.
So not one or more, not zero or more, but let's say three, in that case, you use that and the number
of characters you want to match.
So let's say three and you gets that p l e.
So we're looking at this expression.
I jumped over this because it has to be that, so I'm going to replace it.
It's a place that's in there and you can also do it like this.
So match from three to six, for example, without the space, sorry.
And so you get that.
So this is not what we want in this case.
So Call US Again is the metal character that extracts all the emails.
Next, we have this symbol, which matches the beginning of a line of a beginning of a string or a line.
Is this this high here?
That's a beginning of a of silver string.
That means if we add that so here, for instance, we're not going to get anything because we are telling
Python to get all sorts of email addresses that are met the first place and the first position of the
string.
So it's not really what we need in this place.
You could be using this in in special scenarios, but not in this example.
Same goes for the end of the string, so this will match only the email addresses of the end of the
string.
Again, it's not what we need this one here.
We use that already, so it is this one.
So it matches a single character or a range that is not contained within the brackets.
So the space is contained within the brackets.
So the space is not matched, but everything else.
So that is not contained within those brackets is matched.
So on the dashes, letters, etc. OK.
This seemingly long expression here is an owner operator.
Let's see how we would be using this.
Let's suppose that we only want to extract the email addresses that have dot com or dot to eat.
So if we had something else here, such as another example that and E and we don't want to extroverts
email address this regular expression would not work anymore because it gets us all the email addresses
to exclude that you want to be most more specific here instead of seeing A to Z.
You delete that.
And so you use parentheses which are explained later on.
In here and inside parentheses, you see question mark a column and then you see on the vertical bar
d e.
Execute that, and you get only those that have come or the eat at the end of email address.
So that is the expression for that.
So that brings us to the last major character which matches an optional expression.
So this is used usually in conjunction with an owner operator, as you saw in this case.
So that is a list of metal characters.
It's hard to remember them immediately.
So you gets better as you use them in more examples, but it's a good idea to keep this list in a place
so you can refer to that as you need it.
So now we're done with this example.
We will be looking at some of examples now so that you get more practice with regular expressions.
So I'll see you in the next few.