RegEx – Regular Expressions (Python)
Video Title: Python RegEx | Python Regular Expressions Tutorial | Python Tutorial | Python Training | Edureka
Hello everyone this is sort of some odd Eureka and in today’s session we’ll be focusing on a regular expressions in Python so without any further ado you let us move forward and have a look at the agenda for today the first we’ll see why we use regular expressions what are
The problems that regular expressions helps us to solve then we’ll see what exactly irregular expressions and then we’ll focus on various operations that you can perform with regular expressions after that I’ll tell you various applications of regular expressions we’ll start with e-mail verification then phone number verification and then
Finally I’ll teach you how to perform a web scraping using regular expressions so I hope the agenda is clear to everyone if you have any doubts you can write it down in your chat box or else you can give me a quick confirmation so that I can move forward all right the
Day says yes so does Theon Jason I you see Java see my UNK update all right fine guys so I’ve got a confirmation from almost everyone so let us move forward and see why exactly we use regular expressions so as I told you earlier is well we are
Going to focus on various problems that regular expressions helps us to solve so this is the first problem guys so over here what happens you have a log file and from that log file you want only date and time and as you know with the format of the log file is not
Understandable to everyone so here’s a guy who only one stays in time from that log file so what he can do he can make use of regular expressions identify the pattern and he can actually get the date and time for that particular log file so this is the first problem we’ll see a
Lot of our problems with a regular expressions help us to solve so if you have understood this you can just give me a thumbs up and I’ll move forward alright fine guys so I’ve got confirmation from everyone so we’ll move forward and we’ll see the second problem
Now this is a second problem that it helps us to solve imagine yourself as a salesperson and you have a lot of email addresses and a many of them are fake so what you can do you can make use of regular expressions and all the email addresses have a particular part and
They have a format so with the help of regular expressions you can verify that format and you’ll get to know what our email addresses are correct and what all email address is a fake what so as you can see obviously Etsy komm is a fake email address so using
The pattern that is there in all the email addresses you can verify whether that email address is correct or not to be help of regular expressions alright so let’s move on and see what are the other problems so this is the third problem that it has to solve we’ll take
The same sales guys example that we have taken in the previous slide now over here that guy has a data of various customers phone numbers and we know that a lot of time people don’t give the correct phone number because nobody wants a sales guy disturbing them at our
Timings right so that sales person has a problem he wants to know that what all phone numbers are correct and what all phone numbers are fake so every correct phone number will have a particular pattern or a format so using regular expressions he can identify what our
Phone numbers are correct and what our phone numbers are wrong and at the same time different phone numbers that belongs to different countries or different location will have a different format so again taking that thing into consideration he can again use regular expressions and identify to which area
It belongs to now in this particular example what I’ve shown you is I’ve shown you two geographical areas one is India another is USA so with the help of regular expressions you can actually find out what all phone numbers belong to USA and what all phone numbers belong
To India so I hope this is clear to you so this is the fourth problem guys now over here what happens you have a student database and that contains name age address now what happens there are a lot of students who live in a particular
Area and the area code of that area is five nine double zero six but what happened the area code has been updated and it has become five nine zero seven six now if you go manually update that for all the students I will take a lot
Of time so instead of that what you can do you can make use of regular expressions and find out all the area codes from the student database and after that you can replace it with the updated area code of the pin code so as you can see with regular expressions you
Can even replace a particular string so I hope all the problems that we have discussed in now are clear to you or it’s a Devon says yes so dusty on Jason Sarah I you see jaggedy OBE – monk alright fine guys so we’ll move forward and we’ll see one more reason of using
Regular expression so now this is one more reason to use regular expression because even if you don’t have a Python background if you have any other programming background like Java PHP C has groovy swift Ruby you can use regular expressions because it is compatible with all of these programming
Languages and it is even compatible with JavaScript although it is not written here but yeah it is even compatible with JavaScript so till now we have seen various reasons to use regular expressions but I know you guys must be wondering what exactly regular expressions is right so don’t worry guys
We’ll move forward and we’ll see what exactly regular expression is so a regular expression is basically used for describing a search pattern so you can use regular expression for searching a specific string string in a large amount of data you can even verify that that string has a proper format or not you
Can find a string and replace it with another string and you can even format the data into a proper form for importing for example so these are all uses of regular expressions now over here I’ve shown you an example here there is a string which is present in
Which they have written Janus is 22 and theon is 33 Gabriel is 44 and Joe is 21 so as you can see what are useful data that I can find some here only name and age I don’t want the rest of the things that are present in this string so what
I can do I can identify a pattern and with the help of regular expression I can convert that to a dictionary and in that dictionary only the name and age will appear now my question is to you all guys can you identify a pattern in
Order to get the name and it just give a guess you just need to identify the pattern alright so Sarah says all the ages are in the form of integers all right Sarah that’s a very nice observation but what about the names all right so I’ve got a couple more answers
And they say the same thing that the age is represented with the help of integer numbers so you can get the integers for the name they have no idea how to get it though are you guys it’s totally fine just give a guess alright guys so let me tell you so
Basically if you notice that every name starts with an uppercase first letter so the first letter of all the names is an uppercase letter and then we talk about age all of the age are represented in numbers so what you can do with the help of regular expression you can actually
Find out the two-digit numbers and at the same time you can find out the words that starts with an uppercase letter and then it goes on to lowercase letters and this star actually represents all of them so you don’t need to worry about the syntax that is there in front of
Your screen I’ll be actually explaining you these things in detail so you don’t need to worry about that so I hope you have understood the pattern that I’m telling you all right so we have a question from Devon he is asking what is this may contain a name of a place
Alright Theon so this string does not contain a name of a place that’s all I can say right now if there was a place present here then you have to look for a different pattern at that time so basically with reg X you have to make sure that you identify the pattern for
The string that you want so it is very important so let us move forward and I’ll open my file Chum and I’ll tell you how to get a tan name all right so let’s do it so this is my Python guy so over here
What I need to do is I need to first import the module for regular expressions for that I’ll type import Ari and now I’m going to type in the string that was there in the example so I’ll type in name is equal to and now I’m going to write it China’s is 22
And Theon is 33 now the next line I’ll write Gabriel is 44 stuff about the space and Joey is 21 now close it so now for age I’m going to type in ages equal to now you don’t need to worry about the syntax that I’m going to write I’m going
To tell you all these things in detail so this is just an example that I’m giving you that with the help of regular expression you can actually get the name and age after that I’m going to discuss each and every operation in detail so what I’m going to type in you don’t need
To worry about that I’m just showing you that you can actually do it I’m just giving an example re dot find all are three because all of my ages are two digits out of two digits and then write the name of the string and four names
What are you going to do we’re going to type in names equal to similar to that re dot find all or and my first letter is an uppercase letter that is between A to Z after that I have lower cases so I’m going to type in 8 is it in lower
Cases and then I’m going to put in a star that largely insuit all of those and finally the name of that strength that is naming now what I’m going to do is I’m going to define our variable and I’m going to name it as age state equal to curly
Braces let’s keep it empty right now and now one more variable I’m going to define that is actually equal to zero now I’m going to use a for loop I’ll type in for each name in names aged eight each name is X X plus equal to 1 now print this
Edge ticket yeah so if you’re not able to understand what exactly for-loop is and what are dictionaries so you can go and watch the previous tutorial videos and Python and then come back again go ahead and execute this so yep you have got the dictionary that includes
Only name and age of that person so what I’ve done here is what is the pattern I’m repeating it again so for all the names the first letter is an uppercase letter and all the edges are expressed in terms of numbers so using that pattern I have got only name and age so
This is just an example we’ll actually see how to perform various operations using red X or regular expressions so I’ll go back to my slides or if you have any doubts you can ask me right now so there are no doubts so let us go back to our slides
Now let’s move forward and understand the cursor operation of regular expression so basically in both strings and regular expression both of them have their own cursors so what happens is suppose you are searching for odd and you’re at regular expression includes R so your cursor is at R in the regular
Expression but for text it will check for B it is not equal to R then e then e then again and it comes to R it will see that this is what you are searching so it’ll stop right there the moment I search for s it will go on
And will come towards s and same goes for n as well so this is a pretty basic operation but it will really help you to visualize how things work with regular expressions so guys if you have any doubts with respect to what is regular expressions and how things work in it
You can write it down in your chat box although this particular slide is pretty simple to understand I am just telling you how cursor works in regular expression this will basically help you to visualize how things work alright so everyone’s clear so we’ll move forward and we look at various operations that
You can perform with regular expressions so first we’ll find our void inner string so we have a string that says we need to inform him with the latest information and we need to find the word inform so let us go ahead and execute this practically I’ll again open my
Python so this my Python guys let me just first clear it so let’s begin by importing our regular expression modules for data type import our E and now we have a sentence and we want to find a word in form there so what I will do
I’ll just type in if re dot search and farm and our string is we need to inform him with the latest information so this is our string give a : and now I’m going to type in print this is in form so let me tell you what I’ve done
Here first I’ve imported the regular expression module and after that I’ve defined a condition which says that if it is able to search in form in this particular string that is we need to inform him with the latest information then it will print there is inform otherwise it won’t print anything so as
You can see that inform is present here so it should print there is inform so let us go ahead and execute this so yep you can see that it has printed there is info now let’s be more specific and suppose we want to find all the matches
Here so let’s write a method that will do it for us so for that I’m going to use find on which will return a list of matches for me so for that what I’m going to do is I’m going to write in here let me first remove this and now
What I’m going to do is I’m going to write in all in form which is nothing but a name that I’ve given you can give whatever name you want re dot find all and I’ve told you earlier as well find all will return a list of matches now
Over here what I need to find I need to find in form from which string the string is we need to inform him with the latest information all right guys and so now I’m going to type in a for loop which says that for I in all in
Form give a colon print I that’s it so now what I’ve done here you can see that I’ve imported the regular expression module then I’m using final in which it will return all the matches and what I’m finding I’m finding in form and from which string I’m finding in form this is
The string that I’m using and I finally I have used for in order to find all the matches so let’s go ahead and execute this so yeah it has found in form twice because you can see that it is available here as well in form and even
Information over here you can see that in form is present so this is how basically you find a void in a string by the help of a regular expression so if you have any doubt still here you can ask me or else you can give me a
Confirmation so that I can move forward and explain you other operations that you can perform with regular expressions any doubts case so Devon says all clear so does Jason Theon Sahra are usually jogging T alright spine guys so let me first go back to my slides so we have
Seen how to find a word in a string next we are going to understand how to generate an iterator so basically what I’m going to do is I’m going to get the starting and the ending index for the word that I’m searching over here I’m
Searching in form so it will give me the starting as well as the ending index for all the matches that it finds so let us go ahead and execute this practically I’ll open my Python once again let me remove all of this and over here I’m
Going to define a string so what I’m going to write here is I’m going to write here we need to inform him with the latest information yeah so now what I’m going to do is I’m going to generate an iterator by using finite Reiter and it is going to return the I
Traitor of the matching object so basically I will be printing the starting and the ending index of the matching object so for that I will use the for loop so I’ll write in for I in re dot find iterator and I want it for
In form so I’ll just type in in form and now I’m going to type in the name of the string that is STR : now I want that to be converted into a tuple so for that I’m going to type in log top equal to I dot span
And finally friend lock top so basically it will print the starting in the ending index of the matching objects let us see if it does that say up so as you can see that for in form the starting index is 11 and the ending index 17 for
Information it starts with 38 and ends at 44 so this is how you can actually generate an Idolator by using find I traitor and this will return the starting as it is the ending index of the matching object so if you have any doubts you can write it down in your
Chat box it’s pretty easy guys any doubts Devon says all clear so does Jason Davion alright fine guys so we’ll move forward and we’ll have a look at the other operations that you can perform with ray X so now what I’m going to do is I’m going to match words with a
Particular pattern so we have a string in which we have Sat hat Matt and Pat so now my question is to you all guys what is the pattern that you can see in this particular string that is sad hard Martin part alright so Devon says at is
Common and also the saara jason Theon almost everyone says that all right guys nice observation so let me go ahead with it and I’m going to show you how you can match words with a particular pattern using Reigate so first I’m going to open my pie charm let me remove all this
So let me define a string once more and type in SDR so we have sad mad hot Matt and we have bad this is our string now I want to match anything that ends with at so for that I am going to define a variable all STR and now what I’m
Going to do is are e dot final now what I want I want words that starts with s H M and P alright and after that it should end with at so I’ve written ad it’s very simple guys and now what I’m going to type in I’m going to type the name of
The string that is STR so this bracket where I’ve written SH M P it shows that I’m matching specifically for the words that starts with SH m and T now I’m again going to use a for loop in which I’m going to type in for I in all string
Give a colon print I it starts simple go ahead and execute this and see what happens so yup it prints has Matt and Pat but one thing to notice here guys it will not print side why it is not printing side because it is an uppercase
Letter so if I go ahead and I make it as capital S I’m go ahead and execute this so yep you can see that even sat has been printed so any question the guys you have right now please write it down in your heart box or if you are fine
With it you can give me a confirmation so that I can explain you the other operations that you can perform with regular expressions alright so I’ve got a confirmation from almost everyone so let me go back to my site and see what are other operations that we can perform
With regular expressions now over here what I’m going to do is I’m going to match series of range of characters now what does that mean let me explain you what the example that is there so now what I want here is I want all the words
In which the first letter is between the range edge to M so all the words whose first letter comes in the range edge to M should be printed and it should be ending with at so basically it should print hat and mad because P comes after
M so does s so it won’t print certain path now let’s go ahead and see in a Python whether this half not now over here what I’m going to do is I’m going to remove this s so to speak – and – here and execute this say up it
Has printed hat and mark so if I want all these things to be printed what I can do is I can write in here Z and execute this so you have it has printed hot mat and part but it does not print it side why because it starts
With an uppercase s so if I make it as s and I’m going to print this so yep it has printed side as well because between edge to Z of s H M and P life so it has printed all the range of characters whose first letter is president the
Range edge to Z so now I can use a carrot symbol doesn’t include all the words apart from ones which have the first letter between the range H to M so let me first make it as M and now I’m going to use a carrot symbol yeah so when I use this carrot
Symbol this means everything apart from this range that is H to M go on and execute this and you can see that’s printed such and part but not hot and mad because of the carrot symbol that I’ve just shown you right so I hope you all are clear with how to actually find
A range of characters in a string alright so everyone is clear so I’ll open my slides once again and now what I want I want to replace a particular string so as you can see in the example I have a string in which we have hot rod
Martin Park but I want to replace this rod I don’t like that all right to talked about how it replace this rod and I’m going to replace it with the word food now let me show you how actually you can do that I’ll again open my
Pycharm let me first remove all of this I’ll define a spring I’ll name it as food although there weren’t many food items in it but yeah just for the demonstration purpose hot rod mat pipe now I will replace rat with food so now I’m going to compile a regular
Expression into what are called pattern objects and pattern objects provides us with additional methods and one of which is substitute let me show you how you can do that just type in red X for example yeah reg X equal to re dot compile and I want to compile our which
Ends with at and now in the string food I want to substitute it so I’ll type in reg X dot sub substitute I want to substitute food in which string on a substitute I want to do that in the string food itself so yeah and now finally go on and print it
So as you can see we have hot food Martin part so we have replaced rat with food so this is pretty simple examples that I’m giving you right now but these basics you can actually go on and find out a pattern and you can perform a lot
Of operations so if you have any doubts or any queries with respect to how to replace the string you can write it down in your chat box any queries any doubts case now with this one very important thing that I want to talk about it is called solving the back slash problems
Now let me show you what I’m talking about so I have a string let me name it as a random string so I’ll write it around STR equal to here is Drogba all right so when I go on and print this let me show you what comes so we got
Only single backslash but we have dived in here double backslashes so this is what I’m talking about now in order to solve this problem what I can do is I can make use of regular expressions so let me show you how you can do that so
All you need to do is you need to type in re dot search so this is re is basically we call it as a raw string so Rossing will treat backslashes as special so let me show you how it will do as this type in our dot search then our quotation rod path
And the name of the string that is random string go ahead and execute this up at a solar problem and you can see that double backslash appears over here so this is what I’m talking about the backslash problem if you have any doubts any queries you can write it down in
Your chart box I’ll be happy to help you alright so we have no doubts let me open my slides again and we’ll have a look at the other operations that you can perform with random strings but there you can perform with regular expressions now what I’m going to do is I’m going to
Match a single character so I have one two three four five is match string and now I want to print only the fifth digit so it should print five but before that we’ll have a look at a couple more examples in which I will be telling you
About how to deal with white spaces so let me open my PI term again let me remove all of this yeah so now I’m going to define one more string let me name it as random string equal to keep the blue flag flying high and Chelsea does not aim at my favorite slab
And let me just print this random string so that’s printed keep the blue flag flying high now let’s go ahead and remove the new lines with the space so for that what I need to do is again I’m going to define a variable let me limit
As reg X equal to re dot compile we have talked about compile in the previous example so I hope you can remember it so the symbol for new line that is a backslash n then I’m going to type in the random string equal to reg X substituted with what were you want to
Substituted just a space right so just give a space in between that’s pretty easy and just type in here random string now go ahead and print this random string yeah so as you can see earlier it was like this keep the blue flag in one line flying high in one line chelsey in
One line but with the help of regular expression I’ve replaced the new lines with a space so this is how you can work out with the white spaces so this is how you can work with white spaces now there are other white spaces that you’ll be
Able to work with for example let me just show you so you have a backslash B that stands for what it stands for backspace then you have backslash f4 form feed then you have backslash R for carriage return similarly you have backslash t for tab and you have vertical tabs as well so
For that we have backslash we vertical tab these are the white spaces that you can work with now let’s see how to match a single character that we have discussed in our slide so let me first remove all of this all right so let me define my
More variable and name it as random string again and I’m going to type in here 1 2 3 4 5 and now what I’m going to type in I’m going to type in print matches I’m going to give a : and then I’ll type in length re dot find all backslash D
Random string now over here you can notice that we have backslash T so basically this backslash T will match any numbers any any numbers which are present but if I write a capital T over here so it will match anything but a number so let me keep it as backslash T
And print this and show you what it will give us so we have five matches as you can see that we have five digits now if I make it as capital T so that will return me everything but the digits so let me just show you I’ve converted this
To capital e go on and execute this so we have zero matches now so now if I want to match a specific digit I’ll be using curly braces so let me show you how you are going to do it so in the curly braces just type in 5
And it should print that for us so yep it has found one match that is present over here so I’ll now what I’ll do I’ll clear this again and I’m going to define in one more variables and let it be num over here I’ll go one two three so now
One two three four then our one two three four five one two three four five six one two three four five six and seven now we can even match digits with a certain range let’s say our range is between five to seven so for that what
I’m going to type in I’m going to type in a print statement and again I’ll keep it as matches give a comma and now I’m going to type in length re dot find all what I’m searching for word I’m searching for digits so backslash T and what is my range range is between
Five to seven give a comma and then type in the string name that is now go ahead execute this and it finds three matches because over here we have five over where we have five and six over here we have five six and seven so it has found
The three matches that we were talking about so this is all you can perform basic operations using a regular expressions so if you have any doubts any queries you can write it down in your chat box I’ll be happy to help you guys any questions
So we have no questions so let me open my slides again now we have seen all basic operations that you can perform with regular expressions now how about I show you one of the various applications of regular expressions I’m going to take in some use cases a problem statement
And I’m going to show you how you can use regular expressions in order to solve those problems how about that guys alright so I see a lot of people are interested in that so without any further ado let us move forward and see how you can do that alright so we have a
First problem in which we need to verify these phone numbers so we have a list of phone numbers and the general format of a phone number is it should start with three digits then an – sign then three middle digits and the three digits in
Between and a sign and then fold is it in the end so this is what a basic format of a number is so let us go back to our pycharm and verify these numbers with the help of regular expressions let me remove all this so before I start
Writing down the code let me explain you something so we have backslash W so basically what it does is it is same as writing down lowercase a to z uppercase a to Z even numbers and underscore so lowercase W is actually equal to this thing that has typed here so it will
Match anything that is inside the brackets when we talk about uppercase backslash W it will match anything but the things inside the braces so it is similar to using a carrot inside the brace so I’ll just show you so it’ll match everything but the things that are present inside the bases so
This is what I’m going to use in in order to write the code for validating phone numbers so let me just make a string that has my phone numbers so I’ll just type in our phone and I’ll put here for one two triple five and say one two
One two alright now I’m going to use the condition statement that says if I dot search so anything that has three digits then it should have a – sign then again anything that has three digits then again a – sign and anything that has four digits
Give a : go on and print it is a phone number now basically instead of backslash W I can even use as backslash T because all of these are digits but let me just keep it as backslash W only and go on and print this so yep it is a phone number
But what if I am going to change here and I’m going to make it as triple five one let me show you it is not printing anything because so because our regular expression says that it’ll take only three digits now as I told you earlier
As well W takes a to Z lower case and upper case as well so even if I replace it with D it won’t matter let me show you go on execute this so yup it does not printed anything but if I go on and remove this one and print it again so
Yup it has printed a phone number now if I would have added here a as well it won’t print that so yeah so basically I wanted to tell you what backslash W is that’s why I’ve written it over here now let me tell you a use case of this
Backslash W as well so if you want to see that a full name is a valid full name or not so what you can do is you can use backslash W at that time so basically if I have explained your backslash W is this is how you can use
Backslash W all right I’ll give you one more example so now let me remove all of this and now we will see if the full name is valid or not basically there should be a space between first and last name so for that I’m going to use a backslash S with the
Same as writing down backslash S that is form feed or a backslash n that is a new line or a backslash R that is a carriage return or a back backslash T that is tab or vertical tabs so it is pretty much similar to that so it is exactly the
Same similarly if I write here an uppercase s can you guess what it will be all right so everybody almost gets it so basically it will be equal to a caret and form feed new line v /r tab as well as vertical tasks so it will include anything but
Backslash s backslash n backslash R backslash T and backslash we let me just comment this all right so now let’s go ahead and validate whether a valid full name is present or not so for that what I’m going to do is I’m going to type in a condition if re dot search
Now over here what I need to do is can you guys tell me all right the first I’m going to type in W and range of W should be between to 220 then in between I want a space so I can just type in us now in between
What I want I can have either a new line or a table or a vertical table anything like that so I can give a backslash s and one more backslash W for the last name and the range of the last name can be from 2 to 20 and finally I’m going to
Write the name I’m going to delight my own name give a : and print full name is valid go ahead and execute this so yep as you can see that I’ve printed the full name is valid so if I convert this lowercase s to an uppercase s it will basically be
Equal to a carat and form the new line vertical tabs tabs so anything apart from all of these so I hope you have understood the concept that I’ve explained you till now if you have any doubts or any questions you can write it down in your chat box and it out guys
All right so we have no doubts so now I’m going to move back to my presentation again so now this was one use case now a second use cases we need to verify the email addresses so our email addresses should I want to 20 lowercase and uppercase letters numbers
Plus period underscore percentage plus minus it should have an ad rate symbol then again to 220 lowercase and uppercase letters numbers plus period and – then we should have one more period and then at two to three lowercase and uppercase letters so let me go ahead and show you practically how
You can do it let me remove all of this and let me first write a list of emails so you can write that sk after 800 l.com I can have MD ad rate.com add rate SEO calm now I can have one more and I can name it has TC added dot-com
Let me just remove the space all right so now what I’ll type in I’ll Drive and print email matches give a : laughter the space I’m going to type in length re to find all open the parentheses and over there in the square braces for a1 first I want
Anything then I want a period our underscore percentage + – close the braces and it should range between say 1 to 20 after that what I want I want add it after after it I want anything to that I’ll type backslash W dot times period then I want a – and what should
Be the range it should be between 2 to 20 characters after that I want a period and then I want uppercase and lowercase letters then it should range between 2 to 3 email all right guys go ahead and execute this so it has found only one
Match so which is SK at the rate a will calm now if I actually copy/paste this once more in the end and print this say up we have two matches so this is how you can match the email address you just need to identify the format of it and
You can do it any doubts any queries guys you can write it down in your chat box any questions all right so we have no doubts now let us move forward and see the third application of Python regular expressions so you can perform web scraping using regular expressions
Now what is that scraping let me explain you with a flow diagram that is there in front of your screen so we have websites right and obviously these websites contains multiple web pages now if I want to create some useful information from those web pages I can use web
Scraping and extract that content and I can save it wherever I want I can save it in an XML format or CSV basically however I want to say so you can do that with Python a regular expressions so in our case what we are going to do there
Is a website and that website we have phone numbers we have addresses so what we are going to do we are going to write a code in order to get only the contact numbers from that and how are you going to do that we are going to do that we have
A regular expression so for that I’m again going to open my pie charm so guys I’ve already written the code so we have imported a couple of libraries in the beginning which are used to perform web scraping I mean they are used basically to read the web page then we have
Findall which we have discussed earlier as well now this is the URL that I’m talking about right so let me just copy this and I’m going to show you to you in my browser how it looks like so this is how our web page looks like
So we have name here we have the address then finally we have the phone numbers now notice a pattern in the phone number we have three digits inside the parenthesis then again we have three digits then we have a hyphen and then finally we have four digits let’s keep
This pattern in mind and we are going to write a code in order to scrape only these phone numbers from this particular website let me close right now all right fine so now you see the URL right so apart from that whatever things that are there
Actually we have covered that in the web scraping tutorial so you are pretty much aware about it so what is this we are basically reading the content that is there in our particular website now we’ll focus on the regular expression part so you know what exactly findall is
We have discussed that now since you want only visits so we are going to make use of this particular identifier and inside the curly braces I have written three which means that there will be three digits inside the parentheses after that there is a space then again
We have three digits then we have a hyphen and then finally we have four digits then save it in HTML STR and then finally print it now let us go ahead and execute this and see what happens so we have scraped all the phone numbers that were there this is how it looks
Like and we made use of regular expressions so you can use regular expressions for web scraping as well fine guys this is it for today’s session if you have any questions any doubts you can write it down in your chat box I will be happy to help you Rajani say the
Amazing session Thank You Jean it’s for those kind words any questions guys you can ask me fine if we have no question so I’ll just move forward and give you a brief summary of what all things we have discussed in law so first we understood why we need regular expressions and what
Exactly it is then be focused on various operations of regular expressions and then we focus on three applications of regular expressions starting with email verification phone number verification and web scraping so till now any questions guys I’m again repeating any questions you can write it down in a
Child box fine so we have no question so this video will be uploaded into elements you can go through it if you have any questions about you can bring it at the next class or you can ask our 24/7 support team as well thank you and
Have a great day I hope you enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply to them at the earliest to look out for more videos not playlists and subscribe to our at Eureka channel
To learn more happy learning
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Got a question on the topic? Please share it in the comment section below and our experts will answer it for you. For Edureka Python Course curriculum, Visit our Website: http://bit.ly/2OpzQWw
one of the great tutorial ever
👏👏👏👏
thanks a lot
your voice is very convincing. The way you teach is damn good.
Thanks for your kind support
Very well explained.
exceelent
The most important part of video is at 11:13 to 11:52 where they have explained how regular expression work, This alone makes the understandility of the concept very easy and all the examples were well explained.(Although there was one mistake in video)
Thanks edureka for making such an amazing video
Too much helpful and incredible practical explanation ❤❤
pure awesomeness
At 45:53 why it was taken like this in with two '' in (d{3})
loved the session
Thank you so much for sharing this awesome video. Grateful to you @edureka!!
much Helpful , thanks a lot 🙂
thanks a lot bro…upload more videos……….
Nice tutorial thanks a lot
Excellent lecture,thaks for the course
nice info
what is r
Thank you.. Good information
good sir ,very very good thz a lot
great tutorial
Nice
one of the great tutorial ever …..
love indian lessons
Very helpful I spent hardly 2 hour of time and covered this topic completely. Thank you..!
This was fantastic. Thank you!
awesome explanation 😊😊😊
39:48
nice article
Brilliant for starters
Very nice explanation. I found exactly that I want.
Thank you so much.
Brilliant explain <3
Thank you very much ! God bless you 😊
How do we replace a string
the example you used "Sat, mat , pat hat", it is clear why to use r"[smph]at". but what if we have words like "skin, din, pin, spin" all these words are ending with "in" but starting is little complex. And if we want to find only "Skin" and "pin", How to do it here????
What is the significance of 'r'?
re.findall(r'' ", string)
🙂
What's the regex for finding words that end with the letter "s"?
What does re.compile do? Pls expain
Regular expressions concepts explained very well, really helped me for the exam preparation, thanks a ton
1-Stop Shop Lot of Respect Sir.
Very nice explained. It helped me a lot.
Your way of talking is too good….
Can we use Regex to match pattern between strings from two separate list?
an excellent tutorial. I love edureka
Saludos desde Ecuador! Excelente tutorial 🙂
difference between re.findall[ABCd][ab] and re.findall[ABCd]ab