FUNCTIONS IN REGULAR EXPRESSION - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in the previous sessions we now completed the object-oriented concepts in Python programming and today we discuss about the one-fall concept in Python programming there is a regular expressions right so coming to the regular expressions so it is nothing but a sequence of characters user for pattern matching right so it is a sequence of characters eautiful pattern matching see the sequence of characters is nothing but a space so we can consider one string and this pattern is again it may be a character all group of characters four characters so we are supposed to find whether the given pattern is available with the sequence of characters that means in the given string this process we call it regular expression for example consider an email email I'm sorry email so we can write into the email as some right see so if you want to validate this email we know that every email will be having the enter it's simple at the same time one dot okay so until it must be good at the same thing dot will be there so in order to get this email validation we have to search for the pattern that at least one internet symbol should be match and it is one dot should be available in this text right so if this satisfies we can say that it may be an email address so such a value of things we call it as a regular expressions so pattern matching simply we can say as pattern matching and this is implemented by using the Reg X module okay so English will use the re package or a package to implement the regular expressions so whatever the programs we have writing regarding Cesario expressions also we have to import the package of our e are these stands for regular expression right so this would be important and in this there are different concepts so also we are supposed to see the meta characters and the special sequences so in this session we will go with the basic functions available in this regular expressions functions or methods so there are a few methods available in this rare expressions so first we will go with the theoretical part and then we will show the practical implementation of all those methods in the interpreter right so the first method so these are the functions available the first method is find all find all okay so find all so if you remember list of all matches list of all matches right the second one search function search function it will return match object so you do not return any result it will become match object okay match of this if like the third one is split function split so it will split the string it's given of the given pattern so maybe maybe one split or a number of speaks and the fourth one is sub function sub function is used for substitute a new string word string so this can also be one match or multiple matches right so that depends upon them this sub function so these are all the functions available in regular expressions so particularly in the search it will it will not give the actual result it will return the match object again this match object the match object will be having different methods in order to display the result so one is the start method span the third string start method will you the position of occurence position of occurrence and the spend with you a tuple of start and end positions of Max and Steve will return the actual string user full title match right so don't worry so I will execute each and every method and I will explain you all right so these are the few methods available in this regular expression so find our search and again only for such function there will be a match object the rate that doesn't give you the match object in order to get the result we have reduce the letters of a match object like star spanning right so whatever the function we are using that should be called with the help of our he that should we call it the help of our me that means if you use this final we have to use our yield dot v dot v dot cell or need dot split I need dot some okay so I'm going to this see the exist we show the implementation of all these methods so first one is a final so find that means Arne dot find all so give the pattern so which we have to search comma and the source of string from where we have to so stain where we have to search for this pattern so this will give the list of matches if it doesn't match so if match exists and it will do and this it will return and English if match doesn't exist so if it doesn't have any a pattern in but given such hosting whatever really empty list will be created as a result okay so this is all about this find all don't do this I'm just giving the syntax then we'll see the implementation the second function hardly got searched here also the first argument is a pattern so whatever the pattern we have to check come the source of string so system so that means from there they have to search so it will result the match object if exist match exists and money if doesn't exist the match doesn't exist it will later man okay and if match exists it will use the match object that works for the first occurrence the first event so first occurrence only the first occurrence will be displayed so I will give you the example right so in the implementation part and a third one result re dot split so that means the company string will be splitted into defect elements of a list so with the help of the delimiter given so again we have to do the delimiter all equally here we can also give the pattern so here we can do the pattern so at that particular time from the source of steam from the source of string and the company's max sweet max is please so this is an optional one this is an optional one right so that means how many splits you should be done in the given string should be specified in this max rate it's an integer right so in television so pattern so whatever the pattern here we are giving it will search for the pattern in the source string and it will split that first thing from this pattern itself so for mining splits you should be done the difference of the max explained we are giving me this is an optional she doesn't give this off this nicely it will it will split in all the other tenses of this sauce so for example if this matter pattern matches you in five five places five matches are there all right so fine police will be there five splits will go ahead so wherever the man pattern matches with the store so string that particular term will be splitted and form say East populist okay so we show you the example and this isn't max if it is an optional thing and you Ashwin is a very dotsub pattern come on new pattern or new string this is a whole pattern of old string come on so system from the source so here you have to specify the source of stream and again without mention so again the year the fourth is an optional it's an optional so if you are not matching in this number of occurrences automatically for all the matches for all the fences the world pattern will be replaced with the new para substitution right so here if you give the number of occurrences if you specify the number of occurrences that many occurrences the world patterns will be replaced with the new pattern okay and this is our slow this is an optional method or a function spirited self that last argument is an optional document so max is like any number of occurrences right so these are all a few functions available in the e-reader expression package so let us off here and we'll see the implementation part I will show you by executing a small program demonstrating all these functions right so including this is a find all service pleats up as well as the methods of math object that means the start or span or string right so in the next session we will see about the meta characters and sequences right so let us move on to the system I will give you almost equal binding a small program right more to the interpretive elements so this now we have seen that regular expression but there's available in regular expression so we'll see the practical implementation of all those methods so in order to implement those methods first we have to import our he module which is nothing but a regular expression and then we can we have to implement those methods so we have commonly seen four methods that is the final third split and sub so first when you go with the final so let us take once string string is equal to let it be and if starting with a string which we are taking in best react so after that we have to use the find out so re dot find all so whenever we are implementing the method of regular expression we have to call with corresponding model name so our a dot find all we have to give the subsequence that means a pattern see here you can see the intact pattern string and flags so pattern we have to do so I will give a Fatima's e so I'm supposed to find V T and string right so now let us print this X so that we have to get then list of all the subsequent it means all the given patterns in the string so I will say this one and then we can execute the program so that you will get the output so I'm sharing the program as a regular dot P well so now if you execute this program so we get e e that means that now whatever how many occurrences are there everything will be displayed in terms of released right so here in the given string the alphabet E is available in two times so that's why we've got to see once again I will if you find it a and again we will get the answer as e because in the given string there are tools and also not only the single alphabet you can also view group of characters right you can be und there is only one occurrence of und so it is displayed in the list of one element if I am finding I just want to find the pattern which is not available in the string so if it is not available in the string automatically we will get an empty list get an empty list so the result of this find all function is a list of occurrences right so this is all about the finding find all and then we will go with the search search method virtual for fame for searching the given pattern in given string so first it by that first parameter is a pattern we need to find and the second parameter is the source that means from where we have to fine so let us execute this search method the second method C we will get none if if the pattern is not available in the given string we'll get in none as a result and if you are finding some s what we get C it will return the match object so which I have in the session so it will give the complete object name object name right so this is an object name the first occurrence first occurrence so if you want to get this one we have to use the methods of match object right so once again I am saying this is search function will return the match object so this is not an result it's an object right so if you want to get the result we are we need to again implement some more methods in a match object for example the result will be in the X that means the match object will be told in X so if you write this method start then we will get the result the actual result c00 mean play index value of the given string right first occurrence of this given pattern so yes we are giving so it's is available in 0th position so first occurrence it will return see the start will view the actual result that means the start is a method of match object right so see for example if you go with a deal you got our opposition three third position so zero one two and third position D is there it also similarly there not only the single character we can also pass a group of character right C sorry so I'm searching for the patterns already if you this one will get eight that means e this or this pattern starts from the eighth position say let us consider one two three four five six seven and eight eight position filter and there is a one more method to get the result that is a span which gives the range of given pattern right so for example if it is already so if you run this one you will get a span that means this is a starting index and end index of the given pattern so if the given string Sarathy that means given pattern is starting from this index and n at the this index this means this excludes the end index so 8 to 14 so let us count 8 9 10 11 12 13 14 so 14 is the last index so if we give it 15 right so any index we should avoid so this is a span right span or if you give simply a string automatically the string will be displayed so whatever the result we are getting that complete string will be displayed right it doesn't give any positions or any spans so it will display the complete string and similarly so this is stream start span all these three are the methods of match object this mat of match object will be the result of a search function right so only search function of a regular expression will give the result as a match object so in order to get the actual result if you get if you want to get the position we have to use its pad method if you want to get the range of the given pattern you have to use a span if you want to get the complete string we have to give this string right so this is how we can implement the search function in regular expression so we'll go with one more function that is split function so split function will take the two arguments one is a pattern one is a pattern and other one is the source listing so this function executes so first it will finds the given pattern and at that particular instance it will split the completation let us take an example so you got this one some dig and this space because sorry the last one right if you give some s now will guilty see s is removed wherever the S is there there will be discreet in your beacon okay so if you observe here Sunday's are there is a given thing so L first s is there so it has been played to first term so unión de EP the second term including the space and si are ADHD so yes will be removed in ER a DHA is one and if you give a normal space as a delimiter so it will split whether where there is a space so in the given string after Sunday there is one special it is splitted with two words two different words so if you remove this one every character will be splitted okay hope you understood it or not and we are not also mean we are not giving even a space as a delimiter just open present from flow I mean over appearances and sorry open call send or close or false so we will get the complete every character is excreted every character suspected right so next step one more thing is there here I am reading this is the funkiest King I'm extending the sting Sanjay Patel days and youtuber so here I will execute this one so it will split at the space see what's relevant Sandra BRB needs and youtuber so there are five elements in the list because here we are giving the delimiter as in the pattern as space so we can give the third parameter also that is max is little max splitter so how many split seat bond so if you give one only one speed will be there the first wherever it finds the foster space that will be splitted so if you execute this one you can get an example clear idea see something after that the space so only one speed 2 is required that means maximal plate right here we are giving at 1 so all the remaining text will be kept as a second element so some deep and second element is are these n youtuber and if you give here to the maximum splits will be 2 splits so that means the two places will be splitted sandhya hobby and third element is all the remaining text will be in a better position hope you understood this max splitter so split function it takes three arguments so one is your first one is a delimiter where we want to split and the second one is the sources team from where we have to read these and the third one is the max is greater so third one is an optional if you if you are not missing any max splitter automatically it will split all the trenches right so this is the split function and there is a last function we will go with the last function that is sub that means replace simply the sub function is nothing but a big place so first of all is the pattern which we want to I mean substitute and the next one is a target substitute okay and if you execute this one so these this is the fourth function sub dude sub so we in the string variable the letter yes that means wherever the pattern matches that will be replaced with the given map given pattern right so here I am replacing yes with our okay just a minute so here we have to pass a third argument sorry we have to pass there okay I have to pass the source string so from where it will have to be replaced see in the given string s is replaced with our okay right so which we passed the argument here see the fourth argument is an optional that is nothing but the number of utterances where we have to replace this string so here I am replacing the s with our in the given string for only first occurrence so only one s will be only one s will be substituted with the given R so if you give here for example let us take some a is replacing beta-catenin and if you give you the fourth argument as an optional so it will replace all the occurrences of small a with the capital a so if you agree with this one you can observe that so wherever the small letter is there that is really in place with the capital e right so if you give the fourth occurrence I mean the fourth parameter the number of occurrences that means here I am giving to the first two two occurrence is not small ei will be replaced with the captain game so let us say take these see so the third occurrence will remain same okay so this is how we can execute this function alright so I will I will tell you one once again the function that is explained to be about four function so regular expression so in order to prevent this regular expression functions so regular expression means a pattern matching right so regular function the first function is a final so find all means it will take the I mean it will give it will return a list of occurrences all the occurrences right if the pattern does not find so automatically it will as a empty list right empty list next search search function search function will art will give a match object so a match object so match object means again we have to we have in order to get the perfect results again we have to use a methods called start function or stand function or a function so we can use anyone along these one right and these this returns only stop occurrences right and if if we it it doesn't fall it will give the list if the pattern doesn't fall here it will find it will give them mum as a result and the third one is a split prostrate function always is clits the given string with the given delimiter so again here there is an optional argument that is a max is greater so how many splits it should be done right next up worth one last one is a sub so which is nothing but a substitute here again we it takes a three parameters and now is an argument the first one is a replace em in this pattern and the second one is a replace it string so from with which we have to replace and the third parameter is the source string so it will find the pattern in the required string and it will replace with the given string right so here also there will be a put fourth argument it's an optional thing so that means occurrences so whatever the occurrence we are giving in this substitution function that mania transients it will be replaced right so this is all about the regular expression functions right so in the next session we'll go with the meta characters and the special sequences so if you are having any doubts regarding these regular expressions mainly in these four functions feel free to watch out so the comment section so that definitely I will try to clarify all your doubts and if you really understood my session like my session share my session with your friends and don't forget to subscribe to our channel thanks for watching thank you
Info
Channel: Sundeep Saradhi Kanthety
Views: 19,052
Rating: 4.9224138 out of 5
Keywords: sundeep, saradhi, kanthety, java basics, beginners, programming fundamentals, source code, object oriented, oops, oop concepts, set classpath, abstraction, polymorphism, encapsulation, object, secure, portable, robust, PYTHON PROGRAMMING, PYTHON FUNDAMENTALS, interpreter, python applications, regular expression, RegEx, re module, RegEx packages, findall, search function, split(), sub(), functions in regular expressions, regular expression functions, match object, span(), start(), string()
Id: cdgV4iCDWmw
Channel Id: undefined
Length: 31min 15sec (1875 seconds)
Published: Wed Jun 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.