1
00:00:00,630 --> 00:00:02,830
All right guys so this is the thing.

2
00:00:02,840 --> 00:00:09,960
This is what the fourth video on regular expressions I didn't plan on making this many but it is a very

3
00:00:10,350 --> 00:00:13,890
extensive topic and we're still just scratching the surface.

4
00:00:13,890 --> 00:00:22,110
I mean when you start getting into really complex algorithms in patterns it can get really difficult.

5
00:00:22,110 --> 00:00:27,060
So I'm trying to just cover all of the bases here for you guys.

6
00:00:27,270 --> 00:00:30,940
So what I want to do next is amusing the same file here.

7
00:00:31,050 --> 00:00:35,840
I'm going to go right under where we did the grouping with the parentheses and I want to talk about

8
00:00:36,000 --> 00:00:37,170
shorthand

9
00:00:39,780 --> 00:00:42,710
character classes.

10
00:00:42,710 --> 00:00:43,170
All right.

11
00:00:43,170 --> 00:00:49,180
So let's set a regular expression to our lips.

12
00:00:49,200 --> 00:00:55,900
So to our backslashes here and the first one we're going to look at is forward slash W..

13
00:00:56,090 --> 00:00:56,720
OK.

14
00:00:56,880 --> 00:01:01,500
So this is a word character.

15
00:01:01,520 --> 00:01:04,920
And what this is is it's an alpha numeric

16
00:01:07,230 --> 00:01:14,410
character meaning that it can be any letter or any number or it can be an underscore.

17
00:01:14,670 --> 00:01:21,300
So let's go ahead and let's actually try it we have in here these three axes so if we save that that

18
00:01:21,300 --> 00:01:21,900
works.

19
00:01:21,900 --> 00:01:28,580
And what happens is it looks it goes from left to right and it finds the first word character.

20
00:01:28,680 --> 00:01:30,530
And that's what's returned right here.

21
00:01:30,580 --> 00:01:32,030
You can see the three.

22
00:01:32,430 --> 00:01:34,610
OK.

23
00:01:34,860 --> 00:01:39,400
Now we also have another symbol that I didn't mention and that's the plus symbol.

24
00:01:39,390 --> 00:01:46,650
So if we were to just add a plus here and let's let's look at what we get when I save this and it reloads

25
00:01:47,190 --> 00:01:49,890
and it looks at all of the word characters.

26
00:01:49,890 --> 00:01:50,320
OK.

27
00:01:50,340 --> 00:01:55,090
So it's going to look at one or more word characters.

28
00:01:55,110 --> 00:01:57,400
So let's just say pluss.

29
00:01:57,600 --> 00:02:04,260
Plus he holds one or more.

30
00:02:04,350 --> 00:02:07,230
All right so that's the word character.

31
00:02:07,230 --> 00:02:16,220
If I put for instance an exclamation in here and we save that that's not going to match if I put parentheses

32
00:02:16,230 --> 00:02:19,490
that's not going to match if I put a semi-colon.

33
00:02:19,710 --> 00:02:20,150
Nope.

34
00:02:20,160 --> 00:02:24,890
If I put a space Nope it has to be a letter number or an underscore.

35
00:02:24,900 --> 00:02:27,220
You'll see that that does match.

36
00:02:27,330 --> 00:02:34,720
Now at the same time we can do non-word characters by doing an uppercase w instead of a lowercase.

37
00:02:34,770 --> 00:02:41,320
So this will be Norne word characters.

38
00:02:42,390 --> 00:02:42,710
All right.

39
00:02:42,720 --> 00:02:48,580
So basically anything but a letter a number or an underscore.

40
00:02:48,600 --> 00:02:53,740
If I go ahead and run it with an underscore it's not going to match if I put a letter not going to match

41
00:02:53,750 --> 00:03:01,610
I put a number not going to match it put an exclamation that will match OK a space that will match.

42
00:03:01,620 --> 00:03:07,040
Anything else will match the non-word character class.

43
00:03:07,080 --> 00:03:07,380
All right.

44
00:03:07,380 --> 00:03:10,500
So we also have the digit.

45
00:03:10,530 --> 00:03:16,820
So if we do our equals and then and here do a backslash.

46
00:03:16,830 --> 00:03:18,750
D.

47
00:03:19,020 --> 00:03:25,100
So this this is a this will match any digit.

48
00:03:25,140 --> 00:03:29,880
So if we go ahead and we put in a three and save that will match.

49
00:03:30,090 --> 00:03:34,210
If I put all these numbers here that will match the first one.

50
00:03:34,230 --> 00:03:41,130
But if we put a plus just like we did with the the word character it'll match all of them.

51
00:03:41,190 --> 00:03:41,640
All right.

52
00:03:43,360 --> 00:03:48,460
I just want to have both of those in there one with the plus one without it.

53
00:03:49,420 --> 00:03:56,650
So say match any digits 0 0 more times.

54
00:03:58,340 --> 00:04:01,200
Let's see what else you want to do here.

55
00:04:01,200 --> 00:04:04,850
Let's do a non digit.

56
00:04:04,860 --> 00:04:13,660
So just like we have non-word characters with the capital W we can do non digits with the capital D.

57
00:04:21,080 --> 00:04:24,310
They match any non-rigid.

58
00:04:24,420 --> 00:04:27,740
If I were to run this that's not going to give us a match.

59
00:04:27,870 --> 00:04:32,810
If I were to put an e in save that will match.

60
00:04:32,820 --> 00:04:33,890
OK.

61
00:04:34,080 --> 00:04:38,250
So just anything that's not 0 through 9.

62
00:04:38,610 --> 00:04:43,790
See what else we have we have the whitespace character which is slash ass.

63
00:04:43,840 --> 00:04:47,650
It's going to copy that down and we'll do slash lowercase s.

64
00:04:47,680 --> 00:05:00,420
This will be match whitespace character so if I put in here a space and save that's going to be a match

65
00:05:00,420 --> 00:05:04,060
if I put in a tab that will be a match.

66
00:05:04,230 --> 00:05:10,970
If I put nothing that's not going to match if I put any kind of character that's not going to match.

67
00:05:10,980 --> 00:05:11,340
All right.

68
00:05:11,340 --> 00:05:18,470
We also have the non whitespace which is going to be as you could probably guess a capital S.

69
00:05:18,480 --> 00:05:25,770
So this is I will say match non whitespace character so anything in here if we save that that's going

70
00:05:25,770 --> 00:05:26,680
to match.

71
00:05:26,940 --> 00:05:34,430
All right if I put in a space that's going to be null by put in a tab that's going to be null.

72
00:05:35,070 --> 00:05:35,880
All right.

73
00:05:36,610 --> 00:05:40,920
So see we also have the word boundary.

74
00:05:40,920 --> 00:05:43,530
So let's say R E equals

75
00:05:46,130 --> 00:05:49,970
and let's say let's put in here.

76
00:05:49,970 --> 00:05:54,710
Hell the word hell and I hope nobody gets offended by it.

77
00:05:54,770 --> 00:05:58,170
So we're going to do a word boundary.

78
00:05:58,190 --> 00:06:00,090
So dash B right.

79
00:06:00,110 --> 00:06:03,830
I'm also going to add the case insensitive flag.

80
00:06:04,130 --> 00:06:07,840
So this is a word voluntary.

81
00:06:08,060 --> 00:06:13,640
And then what I'm going to do in here is I'm going to say hello actually let's do it first without the

82
00:06:13,640 --> 00:06:14,920
word boundary.

83
00:06:14,960 --> 00:06:17,800
So just the word hell I'm going to say hello.

84
00:06:18,110 --> 00:06:21,750
Welcome to Hell and save.

85
00:06:21,890 --> 00:06:25,040
And you'll see that it's going to match that.

86
00:06:25,040 --> 00:06:30,850
It's going to start with zero with the zero index which is right here because it's matching this.

87
00:06:31,250 --> 00:06:31,570
All right.

88
00:06:31,580 --> 00:06:37,880
Now let's say that we just want to look for the the word Hell we don't want to look for a word that

89
00:06:37,880 --> 00:06:42,870
has those characters inside of it like hello we want the actual word.

90
00:06:42,920 --> 00:06:47,870
So that's where we would use a word boundaries so we could say dash B and save.

91
00:06:47,870 --> 00:06:52,330
And now if you look down here the index is at 18 so it starts here.

92
00:06:52,330 --> 00:06:59,270
It's not finding it here in Halo because it's not a word boundary it's just it's just a word inside

93
00:06:59,270 --> 00:07:00,310
of a word.

94
00:07:00,680 --> 00:07:06,240
All right so that's what we would do if we wanted to use a word boundary.

95
00:07:06,290 --> 00:07:06,560
All right.

96
00:07:06,560 --> 00:07:11,120
Now the last thing I want to talk about is assertions.

97
00:07:12,420 --> 00:07:12,910
OK.

98
00:07:12,920 --> 00:07:16,540
So assertions are kind of like conditionals.

99
00:07:16,610 --> 00:07:19,070
So I'm going to say are equals

100
00:07:22,000 --> 00:07:28,250
and in here I'm going to say X and then open some parentheses and I'm going to put a question mark equals

101
00:07:28,370 --> 00:07:38,090
Y so I know that this looks a little weird but what this means is that it's going to match x only if

102
00:07:38,660 --> 00:07:41,490
it's followed by Y.

103
00:07:41,930 --> 00:07:45,350
OK so let me give you an example down here.

104
00:07:45,350 --> 00:07:50,300
Let's just say we'll just put an X.

105
00:07:50,390 --> 00:07:51,370
So let's say that.

106
00:07:51,380 --> 00:07:52,780
And that does not match.

107
00:07:52,790 --> 00:07:59,040
OK and I could put an X just anywhere so we'll put an X in here and save that doesn't match.

108
00:07:59,210 --> 00:08:05,210
But if that X is followed by a Y and we say that's going to match.

109
00:08:05,210 --> 00:08:07,460
All right so you can do little conditionals like that.

110
00:08:07,460 --> 00:08:19,220
Now if you want to do the opposite in say match x Only if not followed by a Y then we could put an exclamation

111
00:08:19,220 --> 00:08:23,130
right here which usually means not anyways and programming.

112
00:08:23,180 --> 00:08:27,780
So if we go ahead and say this it's going to be null because it is followed by a Y.

113
00:08:27,950 --> 00:08:31,280
But if I get rid of that y and save.

114
00:08:31,430 --> 00:08:34,250
Wait a minute why is that.

115
00:08:34,260 --> 00:08:36,940
No.

116
00:08:37,310 --> 00:08:38,660
I do something wrong here.

117
00:08:38,670 --> 00:08:44,820
I did we want it we want to replace the equals with the not with the exclamation so save.

118
00:08:44,990 --> 00:08:49,570
And now that works and if I were to put a Y then it's no.

119
00:08:49,610 --> 00:08:51,290
All right so those are assertions.

120
00:08:51,290 --> 00:08:57,630
Now there's a lot more you can get into with regular expressions you can get really really advanced

121
00:08:58,430 --> 00:09:01,570
but these are these are all the basics really.

122
00:09:01,580 --> 00:09:07,550
So what I want to do in the next video is i want to take all that we've learned here all the different

123
00:09:08,000 --> 00:09:15,200
you know character sets quantifiers all that stuff and I want to build a form a bootstrap form and add

124
00:09:15,200 --> 00:09:20,310
some validation and use regular expressions and all those validations.

125
00:09:20,330 --> 00:09:28,010
So we want to make sure for instance the name field is between whatever two and 10 characters we want

126
00:09:28,010 --> 00:09:31,610
to make sure the zip code is formatted correctly.

127
00:09:31,790 --> 00:09:35,780
The email address is formatted the phone number things like that.

128
00:09:35,780 --> 00:09:40,330
All right so we're going to take what we've learned and actually use it in a real world situation.

129
00:09:40,550 --> 00:09:40,840
All right.

130
00:09:40,850 --> 00:09:43,520
So that's it guys we will do that in the next lecture.

