Hello and welcome to this section which is regular expressions revisited.
Now we have already learned about regular expressions in one of the sections and this particular course.
But in this particular section we are again going to revisit regular expression once again.
And the reason why we're doing that is because many of the students in the course actually told me that
they are a bit confused.
But some of the concepts and regular expressions.
And they want me to cover that and much more step into a new section and that's why we're here.
So what we will do in this particular section is that we are going to revisit each one of those concepts
which we have learned and I'll try to explain the same concepts in a much more better way by taking
more examples.
So this is going to be the first lecture and we will start with the basic introduction to regular expression.
We will go through what a regular expression is and we are going to go a little bit more into depth
about how regular expressions are formed and why they are actually used.
So without wasting any time let's actually go ahead and understand what a regular expression is.
So a regular expression in formal terms is a sequence of characters which define a search pattern.
Now this definition might sound a little bit confusing.
So what essentially a regular expression is it's actually a sequence of characters which defined the
search pattern.
So what I mean by that.
So let's say you have a certain string.
Consider an email.
So an e-mail looks something like this.
You have ABC which is the user name.
Then you have ADD and then you have the e-mail provider's name and then you have a dot and then you
have com.
You can have and you can have net or anything like that.
So this e-mail can be considered as a normal string.
Now the difference between an e-mail and a username.
So let's say for example now you want to have some username here.
So the user name can be anything.
It can be ABC under school X Y easy and you can also have some digits over here like 0 0 7.
So this is the user name.
And this is the e-mail.
So even though we don't know the exact e-mail or the exact user name of a user we can still define what
does an e-mail look like and what does a username look like.
Because each of them follows a particular pattern.
For example when we are talking about e-mails it has a pattern which looks something like this which
is some characters.
It can be numbers as well.
Then we have at symbol then we again have characters over here.
Then we have a dot.
And then again we can have some characters or alphabets over here.
So that's what an e-mail looks like.
Because it follows this particular pattern whereas in case of user names user names actually follow
this kind of pattern.
So what regular expression is it's actually a sequence of characters which defines a particular search
pattern.
So what we can do here is that if you want to find e-mails in a particular document or text file you
can simply write a regular expression which matches up with this particular pattern.
So now once you understand what a regular expression is and what patterns.
Now let's go ahead and talk something about a raw string.
So what exactly is that all string.
So rostering is nothing but it means pure string.
So what do we mean by pure string.
Is that that particular string should not have any sort of special characters.
So for example there are actually multiple special characters in Python.
We have a special character like backslash and we have some more special characters which actually have
some meaning.
So let's talk about the backslash special character in Python.
So what backslash actually does is that it actually helps you to print something on a new line.
So let's take an example and understand what a special character is.
So if you type and print and let's say if you want to print something like hello and then let's say
you want to print world on the new line.
So what you can simply do is that you can type and slash n and then you can type in the way here
and now if I were to run this school
as you can see Hello is actually printed up over here on the first line and wall is on the second line.
So the thing which is mentioned inside these single quotes is not a pure string because it contains
this special character slash n.
So in order to make this entire string as a pure string what you essentially do is that we use something
we just call as R which actually is going to make this entire thing as a raw string.
So if you notice over here if you look at the syntax right over here this is actually colored as green
because this is actually a string.
This is also in a green color because this is also a string.
But if you have a look at slash and over here it's actually over there and blue just like the print
statement.
And the reason for that is because the slash and right over here is a special character.
So whenever you want to convert or string which looks something like this into a pure string or string
what you can simply do is that you can have an R over here and it's actually going to turn that entire
string into a pure string.
That means it can no longer have any special character which means that the slash and or here cannot
possibly be a special correct because this R is actually going to turn the entire thing into a pure
raw string.
So now in order to check if this thing is converted into a raw string we can again go back and run the
code and see how it actually works.
So let me just save the code and let me just go ahead run this and as you can see when I print this
particular string the string is printed as it is and slash and is no longer treated as a special character.
So that's it for this lecture.
I hope you guys be able to understand what our regular expressions and what is a pure string.
So in the upcoming lecture we are actually going to go ahead and continue learning about regular expressions.
Thank you very much for watching and I'll see you guys next time.
Thank you.