1
00:00:00,210 --> 00:00:06,000
So far in this section we took the boats were regular expressions in the first video, then in the second

2
00:00:06,000 --> 00:00:10,410
video, we looked at an example of a regular expression.

3
00:00:11,190 --> 00:00:15,570
This one in here, we extracted the email addresses from this text.

4
00:00:16,470 --> 00:00:25,470
In this video, we will take a look at the meter characters that you can use to build regular expressions.

5
00:00:25,770 --> 00:00:32,070
And I'm going to go through each of these characters and explain them using the same example.

6
00:00:32,729 --> 00:00:34,800
So you are familiar with this text now.

7
00:00:35,760 --> 00:00:40,260
That's a sort of text variable, and that is the codes.

8
00:00:44,020 --> 00:00:51,730
So we will be changing the regular expression here, the pattern using all these metal characters.

9
00:00:53,270 --> 00:00:55,000
Well, let's start with the first one.

10
00:00:55,240 --> 00:00:59,440
The first one is the dot, a dot is a major character.

11
00:00:59,470 --> 00:01:04,060
You can also call these special characters so metal characters.

12
00:01:04,870 --> 00:01:09,970
These dot means you want to match any possible characters.

13
00:01:10,000 --> 00:01:17,290
It could be a wide space, a comma, a laser lowercase or uppercase, and any other character.

14
00:01:17,650 --> 00:01:22,290
Even the dots can be matched using these dots character.

15
00:01:22,300 --> 00:01:25,030
So well, let's take a look at the example here.

16
00:01:25,300 --> 00:01:27,460
We did use these dots, actually.

17
00:01:27,760 --> 00:01:36,130
You see here what these did, in fact, is it matched any character at this position.

18
00:01:36,700 --> 00:01:46,990
So we had any character, but space, that's then we had it here than we had any character again, except

19
00:01:47,000 --> 00:01:47,580
space.

20
00:01:47,990 --> 00:01:50,280
Then we had any character.

21
00:01:50,290 --> 00:01:53,600
So one single dot means any character.

22
00:01:54,160 --> 00:01:59,110
So it happens to be in our scenario that this any character was a dot.

23
00:01:59,410 --> 00:02:08,470
But even if it is, for example, an equal operator, let's say, and we execute this cell again, we're

24
00:02:08,470 --> 00:02:16,660
going to match both these email addresses because the DOT captures any character.

25
00:02:17,200 --> 00:02:23,770
So you see that it's just so you see that it also matched this equal operator.

26
00:02:24,010 --> 00:02:32,860
But in our example, we actually have dots in email addresses, and that brings us to the second major

27
00:02:32,860 --> 00:02:33,340
character.

28
00:02:33,670 --> 00:02:37,910
This character is used to escape one of the major characters.

29
00:02:38,650 --> 00:02:47,200
So to treat it as a regular character, which means if you put that backslash before a major character,

30
00:02:47,710 --> 00:02:58,300
the dots in this case, and if this first e-mail address has, that's equal operator as a character

31
00:02:58,750 --> 00:03:04,810
instead of the dots and you execute this, we're only going to get to the second email address because

32
00:03:04,990 --> 00:03:10,060
in this pattern, this time the dots is a literal dots.

33
00:03:10,060 --> 00:03:15,010
It's a normal character because it has this escape made-up character in front.

34
00:03:15,970 --> 00:03:21,160
So that's backslash comes in handy whenever you want to escape a major character.

35
00:03:21,460 --> 00:03:27,430
Next, the square brackets, which could have anything inside.

36
00:03:27,670 --> 00:03:32,500
So these three dots are just to denote that the square brackets come with something inside.

37
00:03:32,650 --> 00:03:35,680
So this is an example of the square brackets.

38
00:03:36,040 --> 00:03:39,940
That's metal character, and that's it's another example.

39
00:03:40,540 --> 00:03:49,300
So inside these square brackets, we can put a single character or arrange or characters within those

40
00:03:49,300 --> 00:03:49,960
brackets.

41
00:03:50,530 --> 00:04:01,060
Let's see what happens if we remove this character here and the space and inside the first pair of brackets

42
00:04:01,060 --> 00:04:04,480
we inputs, another executes.

43
00:04:05,750 --> 00:04:11,240
We get the second email address, so another and then we have ETS and so on.

44
00:04:11,660 --> 00:04:18,860
But what if we remove the brackets like that and we execute again, we get the same results?

45
00:04:19,070 --> 00:04:24,650
So what is the point of having those brackets when you get the same output?

46
00:04:25,070 --> 00:04:33,080
Well, when you have the brackets, you can have the characters arranged in any order.

47
00:04:33,380 --> 00:04:37,990
So let's change the place of a and put it off the end.

48
00:04:38,210 --> 00:04:46,520
So in a other instead of another, if you execute that, it's still going to match that string.

49
00:04:46,880 --> 00:04:55,940
So the order of characters, it doesn't matter if all these characters match a string, regardless of

50
00:04:55,940 --> 00:04:58,020
the order, you will have a match.

51
00:04:58,520 --> 00:05:00,410
But if you remove the brackets, no.

52
00:05:03,210 --> 00:05:07,710
You will not get to the scene because this is not a major character.

53
00:05:07,740 --> 00:05:11,550
No, it's not inside those square brackets.

54
00:05:12,030 --> 00:05:14,700
So let's put the brackets again.

55
00:05:15,030 --> 00:05:22,350
Of course, if you remove an order and you execute Steve, you don't get a match because not all the

56
00:05:22,350 --> 00:05:23,700
characters are matched.

57
00:05:25,170 --> 00:05:29,340
That's what I'm trying to explain here that the order does not matter.

58
00:05:29,940 --> 00:05:35,580
Next, the gloss metal character, we already use the glass.

59
00:05:35,610 --> 00:05:37,950
It means that, you know, we had this.

60
00:05:39,780 --> 00:05:46,590
It means match any known space character one or more times.

61
00:05:47,070 --> 00:05:56,420
So that means this first part or the email address codes have at least one or more known space characters,

62
00:05:56,580 --> 00:06:03,210
which could be letters on the scores, dashes, columns, semicolons, et cetera, but not spaces.

63
00:06:04,510 --> 00:06:06,820
Next, we have a question mark.

64
00:06:07,390 --> 00:06:14,410
This matches the preceding element zero, actually, it should be zero or one time.

65
00:06:17,680 --> 00:06:23,880
So see what happens if we replace the plus here with a question mark and executes.

66
00:06:24,520 --> 00:06:33,690
You will get only the last letter of the words another because one matches is the best.

67
00:06:33,700 --> 00:06:35,920
That's this question mark and two.

68
00:06:36,340 --> 00:06:38,500
So it's only catch catches one letter.

69
00:06:39,130 --> 00:06:44,410
Then we have the asterisk, which matches the preceding elements zero or more times.

70
00:06:45,460 --> 00:06:56,230
So the Plus got at least one or more times, which means in the case of class, which was like this.

71
00:06:58,160 --> 00:07:00,470
We got another example, the.

72
00:07:01,640 --> 00:07:08,050
And if we have adults here, in example dot com, we also get that.

73
00:07:08,360 --> 00:07:14,270
But if we replace that to an asterisk and execute again, we get the same result.

74
00:07:14,280 --> 00:07:19,520
But see if we at dot com to this, it's blah blah blah.

75
00:07:21,410 --> 00:07:24,850
We will get at blog dot com.

76
00:07:24,860 --> 00:07:33,050
Also, because the asterisk matches zero or more elements, which means there are zero elements before

77
00:07:33,050 --> 00:07:33,620
the ETS.

78
00:07:34,160 --> 00:07:40,670
So zero elements are allowed to be before the at symbol.

79
00:07:41,450 --> 00:07:42,700
Therefore, we get that.

80
00:07:43,690 --> 00:07:50,980
So if you don't want that, you want to use the loss to get at least one element if you want a particular

81
00:07:50,980 --> 00:07:55,480
number of elements to match a particular number of characters.

82
00:07:56,080 --> 00:08:04,240
So not one or more, not zero or more, but let's say three, in that case, you use that and the number

83
00:08:04,240 --> 00:08:05,680
of characters you want to match.

84
00:08:05,920 --> 00:08:11,350
So let's say three and you gets that p l e.

85
00:08:12,010 --> 00:08:14,290
So we're looking at this expression.

86
00:08:14,680 --> 00:08:18,490
I jumped over this because it has to be that, so I'm going to replace it.

87
00:08:18,760 --> 00:08:23,980
It's a place that's in there and you can also do it like this.

88
00:08:25,380 --> 00:08:31,200
So match from three to six, for example, without the space, sorry.

89
00:08:32,520 --> 00:08:33,539
And so you get that.

90
00:08:33,960 --> 00:08:35,940
So this is not what we want in this case.

91
00:08:35,940 --> 00:08:41,419
So Call US Again is the metal character that extracts all the emails.

92
00:08:42,090 --> 00:08:50,540
Next, we have this symbol, which matches the beginning of a line of a beginning of a string or a line.

93
00:08:50,550 --> 00:08:53,040
Is this this high here?

94
00:08:53,640 --> 00:08:55,530
That's a beginning of a of silver string.

95
00:08:56,310 --> 00:09:04,920
That means if we add that so here, for instance, we're not going to get anything because we are telling

96
00:09:05,130 --> 00:09:15,300
Python to get all sorts of email addresses that are met the first place and the first position of the

97
00:09:15,300 --> 00:09:15,870
string.

98
00:09:15,870 --> 00:09:19,100
So it's not really what we need in this place.

99
00:09:19,110 --> 00:09:23,490
You could be using this in in special scenarios, but not in this example.

100
00:09:24,150 --> 00:09:30,270
Same goes for the end of the string, so this will match only the email addresses of the end of the

101
00:09:30,270 --> 00:09:30,670
string.

102
00:09:30,690 --> 00:09:34,640
Again, it's not what we need this one here.

103
00:09:34,650 --> 00:09:37,320
We use that already, so it is this one.

104
00:09:37,920 --> 00:09:44,310
So it matches a single character or a range that is not contained within the brackets.

105
00:09:44,760 --> 00:09:47,460
So the space is contained within the brackets.

106
00:09:47,880 --> 00:09:50,970
So the space is not matched, but everything else.

107
00:09:50,970 --> 00:09:54,420
So that is not contained within those brackets is matched.

108
00:09:54,430 --> 00:09:59,780
So on the dashes, letters, etc. OK.

109
00:10:00,480 --> 00:10:06,060
This seemingly long expression here is an owner operator.

110
00:10:07,170 --> 00:10:10,290
Let's see how we would be using this.

111
00:10:11,610 --> 00:10:19,860
Let's suppose that we only want to extract the email addresses that have dot com or dot to eat.

112
00:10:20,190 --> 00:10:30,630
So if we had something else here, such as another example that and E and we don't want to extroverts

113
00:10:30,630 --> 00:10:39,270
email address this regular expression would not work anymore because it gets us all the email addresses

114
00:10:39,630 --> 00:10:45,150
to exclude that you want to be most more specific here instead of seeing A to Z.

115
00:10:45,600 --> 00:10:47,030
You delete that.

116
00:10:47,580 --> 00:10:53,430
And so you use parentheses which are explained later on.

117
00:10:53,430 --> 00:11:01,320
In here and inside parentheses, you see question mark a column and then you see on the vertical bar

118
00:11:01,860 --> 00:11:02,610
d e.

119
00:11:03,830 --> 00:11:11,180
Execute that, and you get only those that have come or the eat at the end of email address.

120
00:11:12,560 --> 00:11:14,930
So that is the expression for that.

121
00:11:15,410 --> 00:11:21,140
So that brings us to the last major character which matches an optional expression.

122
00:11:22,010 --> 00:11:29,780
So this is used usually in conjunction with an owner operator, as you saw in this case.

123
00:11:31,000 --> 00:11:33,190
So that is a list of metal characters.

124
00:11:34,120 --> 00:11:37,970
It's hard to remember them immediately.

125
00:11:37,990 --> 00:11:44,770
So you gets better as you use them in more examples, but it's a good idea to keep this list in a place

126
00:11:44,770 --> 00:11:47,740
so you can refer to that as you need it.

127
00:11:48,400 --> 00:11:50,320
So now we're done with this example.

128
00:11:50,620 --> 00:11:57,370
We will be looking at some of examples now so that you get more practice with regular expressions.

129
00:11:57,820 --> 00:11:59,160
So I'll see you in the next few.

