1 00:00:00,680 --> 00:00:02,930 - [Instructor] For this Self Check exercise we'd like you 2 00:00:02,930 --> 00:00:06,190 to create your own regular expression and test it, 3 00:00:06,190 --> 00:00:09,600 and specifically we wanna match a simple street address 4 00:00:09,600 --> 00:00:12,620 consisting of a number with one or more digits 5 00:00:12,620 --> 00:00:16,230 followed by two words with one or more characters each. 6 00:00:16,230 --> 00:00:20,430 So something like 123 Main Street in this case. 7 00:00:20,430 --> 00:00:23,080 So go ahead and pause the video and give that a shot, 8 00:00:23,080 --> 00:00:24,930 and then come back to see the answer. 9 00:00:29,610 --> 00:00:31,910 Okay, let's go ahead and give this a shot. 10 00:00:31,910 --> 00:00:35,640 So first we have to import the regular expression module. 11 00:00:35,640 --> 00:00:37,920 Here is the regular expression. 12 00:00:37,920 --> 00:00:40,630 So we've got a digit character class 13 00:00:40,630 --> 00:00:43,950 that's saying one or more digits. 14 00:00:43,950 --> 00:00:47,100 So the plus quantifier says one or more 15 00:00:47,100 --> 00:00:49,170 of the preceding sub expression, 16 00:00:49,170 --> 00:00:51,680 and that sub expression is a character class. 17 00:00:51,680 --> 00:00:55,150 Followed by a space, which is a literal character. 18 00:00:55,150 --> 00:00:58,490 Then we have two words, 19 00:00:58,490 --> 00:01:01,920 and in our case we solved it saying 20 00:01:01,920 --> 00:01:04,040 that we specifically wanted a word starting 21 00:01:04,040 --> 00:01:05,650 with an uppercase letter followed 22 00:01:05,650 --> 00:01:10,010 by zero or more lowercase letters and then a space. 23 00:01:10,010 --> 00:01:14,280 And then again another word with an uppercase letter 24 00:01:14,280 --> 00:01:16,430 and zero or more lowercase letters. 25 00:01:16,430 --> 00:01:19,490 So let's go ahead and define that regular expression, 26 00:01:19,490 --> 00:01:21,370 and then we'll go ahead and test it 27 00:01:21,370 --> 00:01:25,120 with the 123 Main Street string that we defined up above. 28 00:01:25,120 --> 00:01:26,930 And of course this is a very primitive 29 00:01:26,930 --> 00:01:29,370 regular expression for matching addresses, 30 00:01:29,370 --> 00:01:33,060 because addresses can certainly take many other forms. 31 00:01:33,060 --> 00:01:35,450 But here we're going to use the regular expression 32 00:01:35,450 --> 00:01:37,860 we specified as a raw string. 33 00:01:37,860 --> 00:01:40,150 We'll pass that in as the first argument. 34 00:01:40,150 --> 00:01:43,640 The string we're trying to match against is 123 Main Street. 35 00:01:43,640 --> 00:01:47,100 And when I go ahead and execute that, we have a match. 36 00:01:47,100 --> 00:01:51,620 On the other hand, if we remove the number at the beginning 37 00:01:51,620 --> 00:01:54,400 and try to use that same regular expression, 38 00:01:54,400 --> 00:01:57,780 we get a no match result in that case 39 00:01:57,780 --> 00:02:00,920 because it's missing a key part, 40 00:02:00,920 --> 00:02:04,930 the required one or more digits followed by a space 41 00:02:04,930 --> 00:02:07,520 in your original regular expression. 42 00:02:07,520 --> 00:02:10,310 So again these can get much more complicated 43 00:02:10,310 --> 00:02:13,190 than what I'm showing you here, but we're just introducing 44 00:02:13,190 --> 00:02:16,943 some of the fundamental capabilities of regular expressions.