Biton regular expressions, so this is a very important concept, the very important feature in Python
programming.
So let us go to some practical examples to show you that how these regular expressions can get embedded
using our python coding.
So what's the demonstration?
No regular expression in Python is a very powerful tool, and regular expressions allows us to locate
and change strings in a very powerful ways.
And they work in almost exactly the same way in every programming language as well.
So regular expressions, that is, the regex are used to search for this specific string in a large
amount of data, verify that a string has the proper format in case of email from a checking phone for
from phone number format checking.
We can use this regular expression and find a string and replace it with another string format data
into the proper format and for importing, for example.
So there are different cases where this regular expression can be used.
So important the model.
So for that one will be using import Ardie and let us suppose we are to find this for a particular match.
So such for a B in the string.
So if I read such a piece.
So here we are having the string EBP and the respective string in which we will be doing the searching.
Is that the it was at the apex.
So now if we do this searching, we are finding that there is and if so, when this particular added
or such return are true, then this respective message will get printed.
So let me go for the execution.
You can find that it is getting printed accordingly.
If I go for this one, say, EPB in that case, then obviously the message will not get printed because
it is returning false it.
So that is added such there is a search for a certain string into another given string.
Next, we are going for this one, so we're going to find all this function returns a list of matches.
So Dotty's it to match any one character or Artisphere.
So Dot Will is nothing but one wildcard character, which will be denoting any single character or espace.
So all is equal to Odegaard.
Find all so a dot.
That means that he can have any, any character, any one character or space.
The ape was at the apex.
So if it is the main string.
So for I in all apes, if you go for preened I can get this one as a blank space and apex.
So in this way I'm getting the respective matches, that is, find all returns, all the list of matches.
And here this dot is being used as a wildcard character denoting a single character or space.
Next, we are going for this find Easter, which returns and iterator of matching objects and you spend
to get the location.
So now here you see it is the mainstream, given that it was at the apex and then we're having this
in order to find it.
So now it is returning one iterator.
So that's why we're having this EPEAT dot Dortmund's any character does exist here.
So these are mainstream.
So here we are having some matches and we can get it.
The respective value that is either spent so from which character to which character it is and getting
extended.
So there is a long table and then print locked up.
They are getting printed as a table here.
So now you are also printing the substring from the estimate.
So there is a locked up colon locked up one.
So in this way you are just going for the printing locked means the first index and the locked up one
means the second index and the second index is always exclusive and the first index is inclusive.
So let us go for further explanation one second.
So let me my coat here.
We are getting the output like this.
So now you see when you are printing this locatable.
So first time I'm getting this match ranging from character number four to number eight.
So just come to here.
So it is my character.
Number zero.
One, two, three.
So four, five, six, seven.
So eight is exclusive.
So here we are having the string that is a idot.
So that's what I'm including this blank space here.
So that is my seven.
So eight, nine, 10, 11, 12, 13, 14, 15, 16, 17, 18.
So now we are having this 19, 20, 21, 22, 23 is exclusive.
So that's why I'm getting this one.
So anybody are going for this locked up?
Allegedly.
I'm just retrieving for colon locked up one I'm getting at here.
So four to eight, that means all the characters ranging from location number four to seven will be
printed, will be read as a substring now match one or several letters, square brackets, square brackets
will match any one of the characters between the brackets, not including apparently work Verity's unless
they are listed.
So now here having on one string that is the animal state.
So all animals is equal to adopt find.
So now you can see here we have having list of characters so any one of them can be picked up.
So C are if P so.
So the strings actually does have strings for the matching actually apostacy at the art at the Imit,
DFAT and Bayati.
So that will be sorted in the mainstream.
That is the animal listed so far in animals.
All animals are beginning.
I said go on printing this I so you see we're getting this one as Areti because it is there an oddity.
Is that substring to be starts to šemeta.
If it didn't we have got this one, but capital C.A.T. is not coming because Capital C is a different
character from the small C.
So in this way we are getting this idea that how we can enclose multiple characters with the Heartbreakers,
which will indicate that any one of the characters can be taken from these characters, including within
the third bracket.
We can also allow for characters in range, remember to include apparently workers letters as required.
So animal is still essential to this and some animals is able to adopt, find all so to.
That means CDE up to a lower case and see to him in the upper case and see it.
So now 80.
So now we are having this Attisso C.A.T. will have the match here and then we're having this M80 will
have dementia and if it will have to match it.
So, but it is not having the match because B is not included in this, in this rangers'.
So now in this way, if we go on printing, I'm getting this Katsumata and F.T. are getting printed.
I'm just executing my code.
You are getting my output.
Use this opportunity to denote any character, but whatever characters are between the brackets, so
there is any character but what the characters between the brackets, so so now we're here to see we're
having the CNR within the third bracket and there's not symbolist there.
So other than CNR, so rest of the patterns will be saadet here.
So as a result of that, C.A.T. not becoming an oddity, not becoming in the output, but Imit, DFAT
and Petie can have their matches.
So for I in some animals.
So if you go for print, I'm getting the support that is šemeta if at the end.
Bayati so I'm executing my code.
You are getting the output.
Replace all Matyas, so replace matching items in a string, so all food is this, that is a get met
and bet you can compile a rejects into pattern objects which provide additional methods.
So that is the Odegaard compile, see are it.
So actually we are having this Siete and Arrietty.
So now at having this sub that is, that is actually a substitute.
So Sabry places items that that rejects in the string with the first attribute string bass to the sub.
So now you see up all the rejects.
That is a substitute.
So this wholefood actually this old fool is the main string here and all will be the replacing one and
rejects has got has got initialized with this has got combined with the C.A.T. and Arrietty.
So the C at the end will be replaced by W.L. but empty and will remain as it is.
So now when you are printing this out fool I'm getting this out Matt and bet I think you are getting
my idea.
Next one is about solving backslash problems, so radix, it was the backslash to designate the special
characters and the python does the same insert strings, which causes issues.
So let us try to get this lessler stuff out of this out of a string.
So now here, see, this is my string to be searched.
There is a slash slash stuff, the string to be searched.
So random, mysterious here is less, less stuff.
But if you go for this Adidas Suchi, there is just less, less stuff into the indie register.
If you go on searching, it will find nothing here I can show you.
So it is fine.
Nothing because here this stuff is not the same, whatever we are thinking about.
So in that case, what you can do that to have a slash in my pattern I should use double slash.
So to have double slashes in my pattern I should use false eyelashes.
So is a floor for slash characters we have included and then stuff.
Now we are going to get our output here.
So now you're getting a here and the span is eight to 14.
So this thing can also be written.
Using this one with R stands for the rogering so you can get around this by using the drawstring and
we don't treat backslash as a special character.
So now you see here are stands for the real string.
So now when you are putting this, you are getting the same output as we had in case of four times before
stuff in the third string.
So matching any character is soldat dogmatists, any character, but if we want to match a period,
there is a backslaps period will be used there.
So just consider this one at having this, if not be what I thought.
I thought our dot is DOT and CIA.
So now we are going for this match.
That is that Dortmund's any character and dark means a dot.
So then DOT is any character and the Slashdot means a dot and it means any character.
So this is a pattern.
I've given this a regular expression I've given.
So I will be searching in this random esteve so array in the auto industry.
So it'll be searching and Hyrule getting to matches and then nothing.
But if it be dot I and I thought our dot is so obviously CIA, they are not having the dots in between.
So that's why that is not getting a perfect match.
So the first part is indicating any character.
So as a result of that if is getting tested and then Slashdot is actually not a dot here.
So this is there and then another dot is denoting any characters.
So having a match there and Slashdot denotes another dot.
So this is getting messed here and here.
We're having this dot and that is the only thing that can be matched with this idea.
So that's why if Dot brought I and I thought our dot s idot our dot is to Métis, I'm getting hit.
So now going for this matching white space so we can match any Wildsmith character.
So here we are having this again around is physicalities.
So we have one for this multiline here.
So Print Rende starts to print their respective string here.
You can find that it will print the respective string letters.
Go for this.
Yes, the string has got printed.
Now, what we're doing here, that means we're going for this at compile selection.
So there is a new line character and rejects that substitute.
These particular discussion will be replaced by this single spaced here.
So as a result of that financial print is registered, the total line will get printed in the same line,
in the same row with a blank space as a separated.
So you see the same, same the phone line has got painted with a blank space as a separator, so here
you see in between long and string there was a slash and now it is being replaced by a blank space.
And then between the goes and on, we had one slash in here, but it has been replaced by a single blank
space.
So now let us go for the next one.
That is a match.
Any single number, any single number so they can be used instead of 029 and slash capital D is same
as not 029.
So here we're having this is still one, two, three, four, five.
So if we want to have a perfect match, then I can go for this added dot find all slash D.
That means we are searching for this any digit at any digit in this random store.
So I'll be getting a match for the fight, then I'll be getting a match here four to five.
So now you see if they print this one again.
Without this, Lynn.
So if I go on to executing this, I can find that I'm getting this match for five times or five different
digits.
Matching multiple numbers so you can match multiple digits by following this, following this with that
number of values.
So here to see where having the match five numbers only so we can go for this D five and then one,
two, three, four, five.
So now if we go for the execution, you can find that this is it is a zip code.
That means here we're heading we're having this particular match here.
We're having this particular match here.
So that's why our such is returning.
A true here slash denotes any digit and five denotes the right number of digits.
So here we are having five number of digits out there.
So that's a here.
We're going to get a match.
Yet if you put a character here, if you put a character.
So if it go for the execution, you see it is a zip code.
That text is not getting printed.
So because that is not a perfect match, you are having one alphabet in between.
So you can also match within the range.
So the match values that are between this five to seven digits.
So he had the main string here.
So now we can go for this, find all that is a slash D that is there any digit.
That range will be five or seven, five or seven.
So as a result of that here we're having this five digits.
So now let's go for this match.
So in between this fight in between five and seven, that means in between five, six, seven, I mean
three lengths are physical.
So that's why I'm getting this matchup three.
So here you see we're having this is a perfect match.
This is a perfect match.
And this is also a perfect match.
It has got a length of five.
It has got a length of six.
It has got a length of seven.
So five common seven means five to seven.
That means all the numbers consisting of digits only and having five to seven digits.
That means five digits or six or seven digits will have the match here.
Matching any single letter or number in that case, we can go for a slash W that is the same as A to
Z small letters, A to Z in capital letters and 029 So that is there any letter or a number but slash
capital W denotes a note of them not.
There is a note we are having here.
OK, so we are having on also the underscore is included here, also the underscore.
So now we are having this phone number that is for one to hyphen five five five Haibane one two, one,
two.
So check if it is a phone number or not so we can go for the slash W.
That means that any letter or number, along with the underscore and having the Lintott three, then
one hyphen, then any number or letter we're having this with that we do of three.
That means the three number of such then hyphen and then slash W4 and then phone number I've given.
So it is a valid phone number, so it is a phone number so that we could print it.
So now we can have this check for first name between two and 20 characters.
So first name must be in between two and 20 characters.
So any, any, any name we just having two letters or C two, 20 letters, not only letters.
We are having these letters or numbers or digits will be treated as a valid one.
So if added or such, slash w w denotes small little small Z capital to Capital Z and 029 and also to
underscore so the length will be ranging from two to 20 inclusive of them.
And then Alterman.
So now it is a valid name.
Yes, it has got a valid name because it is having a length which is in between two to twenty.
So now here we are having this white space, so this is same as this and slash capitalis is same as
not of this.
So he can go for this.
So added or such there is there any letter or any digital, including an inclusive underscore having
the length in better from two to 20 and then slashes?
That means that any, any, any one of them we can have and then two to 220 will be the next next number
of letters are the digits are underscored.
Now here is a name we are giving.
So now I shall have to print whether it is a valid full name or not.
Yes, it is a valid full name because it is having the land in between to 220.
It is also having the land in between to 220.
And that is a blank space, is there?
So there is a white space.
We are having it.
So that's why we are having a match and that's why it is a valid fullname.
The respective message is getting printed.
So next one is this one, so now plus matches for one or more characters.
OK, so now we're going for this E-Plus.
That means a single letter A or more than that.
So we are having this is a Buji.
So obviously Buerge is not starting with this.
So now if you go for this Odegaard, find all.
If you go for this or you can go for this, you can have the three matches or a four is for a B and
you can print a match just like this.
So because they are having the first letter A next, it may or may not have one or more characters.
So here we are having this import, Ardino, here we are going for the email address checking.
So that is very important.
You know, most of the projects we might be requiring these regular.
So let me discuss them into some rules.
So create projects that matches email addresses from a list.
And the first criteria will be that one to 20 lowercase and uppercase letters, numbers plus.
And then dots underscore we are having this percentage plus and minus.
So it will be represented in this way.
So that is a slash W then DOT underscored.
But having this one as your percentage plus and minus.
So that is a there's a first one.
Next will be having this is added up symbol.
So symbol is this one.
So that means this one is for the rule number one as it has been mentioned, that it can contain lowercase
an uppercase letters numbers, plus it can have this dot, then underscore then percentage then plus,
then minus.
So everything has got listed and it can be of one to twenty characters such so I mean this one to twenty.
It has been written and then we're having this added up.
Symbols are the symbol is there.
Next we're having this two to twenty lowercase uppercase letters numbers plus dot and our this minus
here.
So now similarly we have written this one.
So here you have this any, any letters and then there is a alphabets and lowercase an uppercase alphabets
and the digits and then dot and, and the minus is there.
So dot and minus and it will be having the list of two to 20 here then will be having one period.
So that is a full stop is there.
And then two to three lowercase an uppercase letters so to a to Z in the uppercase and A to Z in the
lowercase two to three number of and that will be starts in the email list.
So according to this particular constraint, whatever they have mentioned, all of this at the state
of Israel dot com will be a valid email address, but they are not a valid email address because here
is the update.
This added up symbol, there is no character here.
It is not a valid email address because before this added up symbol, there is no character.
And here also it is not a valid email address in the symbols in that after this added up symbol, there
is no character.
We are having directly talked here.
So how many matches we are getting here?
We are getting this matches one.
So that is where Len is actually printing one here and here it is printing their respective valid email
address in this email list.
So in this way, we have discussed that how this regular exhibition can play its powerful role in our
Python programming in most of the projects will be using Python related projects, will be using these
regular expressions and regular expressions that are for different purposes, as I mentioned earlier.
So here is a code I'm just calling up so that you can have a division here.
So a search for a specific string verified the string, whether it is in the proper format or not,
find a string and replace it with another string and format data into the proper form for importing,
for example.
So these are the different uses of this regular expression in our python.
Thanks for watching this video.