Master Regular Expressions in Python with 50 examples | Ashok Kumar | Skillshare

Master Regular Expressions in Python with 50 examples

Ashok Kumar

Master Regular Expressions in Python with 50 examples

Ashok Kumar

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
14 Lessons (1h 7m)
    • 1. About this course

    • 2. Introduction

    • 3. Set 1

    • 4. Set2

    • 5. Set 3

    • 6. Set 4

    • 7. Set5

    • 8. Backreferencing

    • 9. Look ahead

    • 10. Look behind

    • 11. Greedy capture

    • 12. Split function

    • 13. Finditer

    • 14. Find and replace in regular expression

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

A to Z - Regular expressions (regex) using 50 unique examples - you can use it in any language like PHP, Javascript,Java

Unique characteristics of this course

1) 50+ step by step solved examples

2) Interview questions - solved with detailed explanations - This helps you to get your dream job

3) If you are having any queries you can post in Q&A, I will help you out in just 1 working day.

4) You can use the concepts in any programming language like PHP, Javascript, JAVA, Ruby, and so on.

This course will help the students to understand all the concepts of regular expression. In this course, the students will use Python programming language (No need to know the concepts of Python - As I will explain it step by step). After completing the course, the students will be able to apply the concepts of regular expressions in any programming languages.

Register this course and get a certificate on completion, you can also post this certificate on LinkedIn and increase your profile ranking.

Meet Your Teacher

Teacher Profile Image

Ashok Kumar


Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. About this course: - way . 2. Introduction: Holloway's in this video, and then you basic suffering expression. The expression is usedto extract substrates peritus on to use the expression you need three things or Mr Pope Street, another Miss pattern on and this exhibition possums. They put stream character a character based on the pattern on business and Max phone. Then it put those characters into the on the loose patient is very fast, really efficient, and the deal in its stance off the court. So pattern is that particular characters using this pattern renews expression. We extract all the substance that Mantis dyspeptic on. For example, if you take a street and if the pattern is fake, our students off, lend three that starts with you. I know that the next station stop passing the put spin on it. I expect all those possible substance starts and the both of them to speak. And you concede that in this input string Iraq totally four different possible combinations that this before to create them for digital. So if you changed it back, like all strings us lived, who against it? Fine. Then the expression Boston put Stream Captain character Adam C. A possible two digit strings image the last Captain This fight and it is only possible abominations that this part of faith and no si do the suspicion in program first step you must input. And I very call this our and the second wellness. You need three different things. As I told you earlier, the woman's input stream on another illness and that lost you need our food store on the substrates. Let the the characters No the battlements. You must extract the world a funding stream. So the pattern this year see story after for there is a function in our called us are that find all or this except printings post or Mr Pattern followed by a day so you tend to see will get And a point at this that a exhibition fasting upstream on based upon the pattern he makes struck with is percent on it'll be placed in C 3. Set 1: all of this no. See different patterns in regular exhibition. So in this table, the first column shows that different pattern on the meaning of those patents. So 1st 0 slash d. These involve instruments this particular court will match a single digit on If you put a capital lead in, it matters all other things except us in digit. And when it is smashed, w it matches a single are formally character. And with this capital W it Mattis is into character, which is not Al for me and similarly smashed smallest match a single space character onda slash capitalists matter single character, which is Marcus piece. So no, you see this example? So the first tour nous I used the patroness Ashby massive. So there are two slash, please. That means this particular back and matches Oh, digits the tap best in sequence. So when they underscore, you can see that no book contains two digits. Similarly, if you put on here, match are for numeric digits. Well, the first question is being asked matched street food in the foot First let me coffee and place it in painful. Yeah, And since we have to match the character for a battle will be full. So they knew you can found all the force present in the bloodstream. And the second wellness we have to match the spring TV and they put is you want here or no match the captain gave me That happened to be a for baby and then you remember that expression par sustain upstream match on the possible occurance off baby and it will be sold in six. Now the question is, is he must find the strength which starts with it on follow by two. Piece on. Follow Basie. Well, that means first character should be followed by that two organs off the should be dead on at last and see Afghan should be present. So the fact that would be you Rubies and see for the next question is we must match all the strength offline to start Smith, for that means first character should be followed. Give me character. So for a foot slash year, Max exactly and slash new will match Any are formally character. Well, you know, you can see that there are some possible appearance would be on for a day. Any alphanumeric character. Now, the next question is we must match off the streets off three. Which would be that means be last digit should be on before two characters can be present on. There is no restriction for that. So then, in week two slash revenues in your you get Derek Lloyd answers the article The Boston It must start with each meal on the massive. So starting character Sitch on ending is so since the limp Destry the second character, there is no distinction. So, for under slash W will match any other character andan exposed Tunis. They must match on the strings off limpy that has eight in second position for since state put country digit first slash match. Any digit on the second position should be eat. Are there any far away slash Lee Green City match any other? No, no, the question is, was matched the strengths Off went fine, which has four in second position on gate in fourth position, So the pattern is so four should be after second position and he should be at four. So there is no restriction for Foster place, so slash B match any counter at a faster pace on second addiction before don't digit this father station on four did. It should be eight for the last. So the next question is we will find out the springs off. Let food It starts with the digit on me in three digit is a stain foot screen. Norton Let this four that means posted You should be most character should be in digit on. The last character should be in digit between That can be are not limited at this slash Lee , The next question is match on the string off Lend three and as a digit followed by space. Fall of a and non are funny, very character. The first paradox should be in digit on the following day and no one for you very connected . So slash capital, the new match and not we knew them You can get and it back. The next question is we must match all the strings off land for that does not have anything legit in the case. The case, the pattern in the capital D four, Captain even match any single character, this bondage it and then you know you can see that in dance it is more specific 4. Set2: you never quantify it is based before character in extensive character for someone, for example, there are lots of difference in our so first oneness plus plus in the gate step. A particle of character can be defeated one more times and similarly starting percent that a particular character can. The Beat Geno ends on Boston Mark Alosi character Toe a exit one day are gentlemen. Similarly return percent exact number off occurance using a burning bracket on the curly bracket has only one number means that exact. That number should be defeated on If the good cricket has two numbers. Janet the present that stop on in, for example, you can see H J three weapons. There is no different for it, so it should be percent. One time on J can be the Peter Rebeuh fighters on the lease. The current record contains only one are decided for the in it represent the minimum number of officers. Similarly, this having the common followed by a number, then it represent zero to maximum in apparatuses. But the first question ISS must match on the streets. It starts with a V C on intimate or booty. So ask for the Boston. It should start with ABC are your end. So in between there can be any number of characters so far. Dept. Ivan Ooze bash W onda We must give a fortified spot. So this star lows that this last look and very Peter zero or more on the new one. You can see that starting with ABC on ending it on duty. And between zero on this. The next question is we must find all the streets that start OK. Followed by at least one B on the pattern will be starting with E appreciation being present. Only one on followed by a at least one Be at least one. We need species. Really, Peter? At least one pain. So news quantified place for no, we must find on the streets. It starts with a followed by zero more peace. That means we can be absent are it can exist more than one day. This is in fortune for party question. Anyone want himself? It should be it. So far, zero r more beasts Start after the sore spot is a pontiff A for B which states that we can be the future, you know? So the next question is we must find all the substance we start to fight. Are they at most one for? So that means after finding ated, one food can be present or it can be absent. So it is compulsory occurrence off and half the site four can be present Dated one pain are generally so far kept. I used to quantify it. Boston mark on this king's dances For the next question ISS, it must match wonderful engine numbers. It starts with eight. So that means first character should be eat on followed by any digit on this You be present keeps So fortify this back it single bracket So this turn intrepidity person step slash can really Peter three pence. So instead, before Egypt 1st 1 state for any religious So no, you must find the strength they start with me and followed by war disease That means first abstention Be a week I followed that two are zeros so far that quantify It is many moments too on maximum it can be anything So you just tow mama are posted So know this Pontiff ice zero workers who are more steps. The next question is we must match all those cleans with end at least two zeros. So it should end of it. At least two zeros so far. Debt The ending zero followed by two. So this quantifies zero can be present two or more times. Since the substance should individual at least two, it can start with any digit. Well, this brings us slash B mattress and single digit yes is being followed by who are more zeros. So the next frostiness must find on the streets that into our most threes. Eagles first name. What a strange ending it are most, please eagles that this maximum our furnaces. Three. So far, Not really. It's a 25. So slash Stephen Max A single digit. So this permits digit follow. They are most easy on the next question. Ist streets should have a placed. You find ones from third position. There is a stream and we must find Find us a strange yes, at least to find once position so one, so be five times. So since it is based, the third position, the first positions is smashed. The next question is we must find out the strength it start with dual ending with 45 on there is no restrictions off number of trees in between. The that means tree can be present Leader are more tapes. So the pattern in C to start with your on in 45. In between, there can be zero are more please. Then a supposed Tunis he must find on the streets. It starts with two or more. Yes, on end with at least three. These battlements. It should start with two or more of these so hard that on the face to our times, followed by any character so far that smashed you on. This character can be present a little more should end with a placed freebies. So you quantify this tree and mama. 5. Set 3: this video off glasses masses are used to farm each mass, meaning the first message record explain making this usedto match any character this person does. The fact this is this is a match. So this means that it will match anyone. Character. This are on four coolness minus operatives used to mash actors in age. If the skin matched, anyone can mean and fine minus nine matched anyone. Character between fight this Actually. Fortunately, we have a match on the substance e and then first R B. I can't do scant making. So I smashed up for Smash them for a loop because Max and me for the It's again there are aren't most e first, you should be match even a spinning off to N. B. R. Incident. An explosion is we have to master streets that have full fight be And first you should be one Oh, on between in fullest a sportiness we have to find on the budget since then be a possible first digits. Six since it is and most this party needed it are you? You can use it since it is and it's supposed to notice, we have to find our what stops. It's four in this among individual, just one. So if you have the first digit is a sequence one. This will give you no. We must find on the pink digits. Doesn't have the off season. I mean, it's now a contender. Digits 36 So you explain that means match simply. Six. Those history in six. So the coffee is you so like this you can put a turning places. This means just an explosion is fine. That stops me one. So first you should be and exposed Tunis we find on this big soft that stops being so first should be the booby Uh, stuff the therapists can be things Since then I supposed to do this, we must find on before us. So for juice 1st 3 digits the next Fortunately find on before. Not me. - I finally did it. Not the lips. No. We must match on this thing so often. Fight that stocks with exactly three bubbles. So any office, this stuff, this core find on the substance find explosiveness find on the streets doesn't have any. It's fine. Any attack that since we need the week after stream so perfectly match the next question is you must find out this Please stops since you stopped should end him. E have any Stop. No, we must match that. Who hold eight? Not for so no, you must find on this. Thinks that well since the news this on the substance. - But you start means possible for 68 should in the it means possible 13 6. Set 4: Thank you. You somewhat So Here. See that? I used to stop So the first back in fullness on this. So listen matched the spot off the street and $7 matchday in Oh, that way. Have fun which begin So we started so extremely. Start with you will be like for but this Thank you Do not match beginning that there is a instinct that any city such So since we have a match, the springs stops, we have news. So this is the beginning. So they know that I know you can see that second I know be smashed Blue stop is so essential in we didn't receive help The doctor, you see, So get the space with so you know. So get the substance Which is that this so you can see that this particular is most heinous Find stinks in So we have to use this you know so seriously not matched a stream. Exactly. Have so the pattern is the numbers start and so get this fix. I'm since Your Majesty helping this spot off this deep enough. So you get that 7. Set5: I'm not this video C Max. So, for example, if you want to match this you really you slash on the since first ever defend me that displays. It's almost slash me that this posts lasting to be more so this special meaning And so you know Yes, you are defending any, you see, So you should smash behind me. Smash Smash So sure. So this is the biggest. So anything you this I find that it's no match because this place is acting support for first so that this the meeting off this first can be meaning What? This our escape once before It is not this place normal now, This match I plus two Is it on the first questions we find it will be since we need to check So this list, then we'll change. Therefore, I changed the poor using blue this each in the he is me. No question it's fine. All species. So on this place is going to be a quantified partners because we need a friend more than okay, So be for so this match has think so. If you see it's now, so this is you can see that for its bean business to second. The next question is we have to find office space. Just ending any cactus. So use of this since pushing markets, having a defense, the chapel is intact. On the next question. Is the match off? No, that would be the scheme will stop so they can be so that this open plan offices, close practices. So is in that. Well, I mean, you have this. Yeah. 8. Backreferencing: todo cae be more match to sing more than so for example, we want to match three so slash press off slash this match office things off. So I posted it the first need to B c. So no need show that what captain is being matched with first class should be master with so so going back thes so this national the second snatched that for a second and the mosque next forms Now these groups are excusing back slash smashed So it's not just but first slash to the person and feet Yeah slash b The person characters that smashed no intentions to master. Well, simply few meeting This mashed slash on this match takes No, you learned the school you get 9. Look ahead: Hello, everyone In this video, we'll see how to do. Look ahead. Yeah, Look up early in the glens. Freshness matching up actor one or leave. The particular pattern is present after much. So if the pap it is not pleasant after the match, then the matching would not be happening. Okay, so we'll see this example. Let us match the three digit number which starts with a fight. So that meant first digit should be fighting. Followed by any digit so slash B on the third digit also can be anything so again a with you slash b so business match on the three digits. We're just starting with fight. Let me run the score and show you There are totally four matches phoned in the street. No, considered that we want to match three digit number started with a fight. One and only If it this having three after next to position. Okay, So that this This is pre digit match. So after this match, there should be a three. So you for this present, then it should be a match. Other vase. You should reject that much on this is look at their So that is we have to match the stream wouldn't leave then A particular pattern is been repeated after this match. So let's give this pattern. So what they have to do is after giving this pattern, they broke you. They look us in court and look up. The court is given by. But I think it well. Steven. What equal? So this three characters specified depth that is going to be a look at it. So no, we are going to match the stream one leave business a three after that match. So we close this bracket, so not only fade on the score, you can find that data is only one match because for only one match, please being placed after this. Suppose this is unmatched. If I replaced this job, I three so no, we will get to answers in other core. So this is how I look after it works similarly Dallas opposite for look at her instead off you could do if you put explaining what So no what happens is so if three is not present them, there will be a match. So if you put equal toe, you dis positive. Look up there. That means if trees percent. Then there will be a match. If you put expected. Market is called us and negative. Look, that this is a three is not phone. Then there will be a match. So let's run this. So this is the first match Andi even see that it's not three is not being placed after this particular match. So it discarding this. Find out. Okay, so this is how I look forward, both positive and negative works. 10. Look behind: I know everyone in this video you will see how look became work, See little expression and look up. There will only work with a particular match is being followed by a pattern. Look, McCain works in the opposite way that this if a particular pattern is being placed in the immediate loved inside off a match, then that matches be included in the finder. I've been based them, actually, people need it. So suppose you consider that we're going to match all the three digits, starting with 51 Leaving it, this bean followed by a Okay, so here you can see that this is this is a three digit number starting with fight, and it is followed by a two. Similarly, this is a three digit number starting with funny and it does not fall of a book on that is going to be a match here. Also, because pre budget number starting with five years for way too. On that last, this matter is not going to be included because who is not being placed in immediate left and set off this fight or six The hope of do this Look behind this The same bay, helpful start a bracket. On what? The postage month? No, Instead of giving equal, you have to give this list sensible on. Then you have to give equal to sign. I only hope that you met. No, no, that s it underscored on here. You can see there to matters. And all these two mentors has to in the immediate left inside position. Similarly, there is negative in this look became so instead of vehicle to If you replace this idiot explain Italy month, then what it will do it will match one we went to is not present in the immediate left our state. So let me run the score on different See playable eight. Ok, so a business a match and you can see who is not present in the unit left inside So he just getting caught in this fine. 11. Greedy capture: Hello. Base No letter C that hope extract the streets based upon non greedy approach. So come see that example, Mint. We're going to find the strength to start with a on in with W. And we will give the pattern like this. The string should start with the G eight on. It should end with W The Olympic Mini can have any number off characters. So for that I will use slash w stop. So let's underscore. And you can see that the first years matched here SAFTA Dept. W is being matched at this point. So in keeping all these characters are being matched a bit slash The bluestar on this is called us a greedy approach. So when you look this thing closely, you can find it. They're not stuff. Substrates would start VP on end with doubly. Okay, so this is one substrate. Andi, this is under the substrate on this is on a substrate. Okay, so these sleaze offspring start with a on the nvw on the street. Things are not caught with this battle of pattern because abuses greedy a put. Okay, so no, we will see how we will extract these surfactants using non greedy approach. So give non really approach. What? He must do it. So after this slash w stop, you have to give a question. Mark this question Mark Aloes, that when there is W, we have to stop. Okay? We should not continue after w. So what happens when you omit disgusting markets? So this stubbly will be matched? One live with the last occurrence, FW. So rest stuff in a lose a big part of it, this slashing of your stuff. Okay, so do overcome that. We have to give a question, mark. So this question mark follows that the slashed, the global cash, anything except that w So let us underscored in C so long you can observe that the substance have been caught. Okay, so this is how you will capture that substance using really approach. 12. Split function: Hello, everyone. This we d o c Few common motors that be using legal expression package on the first oneness splitting. Okay, so there is a pattern and there's a street on. We need to break this streak into substance based upon this pattern. So that is here. There's so much that means there in tow, Two parts. So one partner contento on their stuff. The parts will campaign this Indian thing. Okay, So I can We are going to find a pattern in this particular speak. So here there is a pattern. So they split from this park toe 1,000,000,050. Right. So this is whole respecting works. So you see this with cool so that you can understand better. So no, we are going to create a variable. See which stores the substance off yet? Jessica Adi Doctor, there is a function split. So this sucks up stooping so Mr Happen on the street when you print this See, you can view all the substance but just being created using this pattern. Ok, so wherever this spat in his phone, there will be a split. So this is called split. What's on here? You can specify how many times a script should happen. So that is persuade with Max Flipped equals group. So that means we're going to split the stink boot camps on. If you're slipped a string pull attempts, they will be totally the substance. Okay, so surrenders pour on the here, they can see there are three substance. 13. Finditer: everyone in this Well, we will see how to get the text location for each match. Find the index location is being They were using the function Pulis find idea So the store index location at sea It is equal toe ari dot the state we're going toe you find ID. OK, so we in our interviews find on so we have to do is find so dismounted Also accepts the first family that as the packed in followed by the street Then we can start a for loop Andi , print the starting and ending location off the match. So that is done with I don't stop. Come on, you don't yet. And this will give the list stuff. Start on the end index location for each match. 14. Find and replace in regular expression: elevates in this video. You see hopeful We place a match with some strings. Apples? This is the street. And this is the pattern we want toe Replace this pattern industry with somewhat cactus seeing a BCP. Okay, so we will see how to do that on real store the replacement in the new spring called C, which is equal to r e dot On there is a function Carless sub. Yes, you be. So this some accepts the captain as the first on then here. Help you Boxley. You were going to replace. Suppose I want replacement ABC. Yeah. So this is just lean. They want to replace on. The important thing has been given as the third. So no, let us print this. See to check whether the replacement has been currently are not so here. We've been finding some locations. Every city has bean the simplest. So the center location severe There is a match for So it removed that match on it will insert a B C. D. Suppose he want to restrict this replacement with some pressure. So you can do this if they give to that means it will just replace to Texas after to think that this starting for payment, the replacement won't happen, right? So let us around this and see. So even if there's a match phone, the replacement is not done because we have limited that replacement should occur. Only put temps.