1 00:00:00,600 --> 00:00:01,520 - [Instuctor] In this self check 2 00:00:01,520 --> 00:00:03,900 we have two exercises for you. 3 00:00:03,900 --> 00:00:07,050 In the first case, we'd like you to replace every occurrence 4 00:00:07,050 --> 00:00:11,950 of one or more tab characters with a comma and a space. 5 00:00:11,950 --> 00:00:15,130 And in the second case we'd like you to split the string 6 00:00:15,130 --> 00:00:16,850 that you see down below here. 7 00:00:16,850 --> 00:00:20,160 And we want you to do that at any sequence of one 8 00:00:20,160 --> 00:00:25,030 or more adjacent $ characters in the string. 9 00:00:25,030 --> 00:00:28,020 So, go ahead and try those exercises 10 00:00:28,020 --> 00:00:29,903 and then come back to see the result. 11 00:00:35,540 --> 00:00:39,210 Okay, let's go ahead and import the re module here, 12 00:00:39,210 --> 00:00:42,780 and here is the answer to the first exercise. 13 00:00:42,780 --> 00:00:47,390 We're going to be replacing the tabs 14 00:00:47,390 --> 00:00:50,830 in the string with comma and space characters, 15 00:00:50,830 --> 00:00:53,840 and here is the regular expression that we're going to use. 16 00:00:53,840 --> 00:00:55,490 Notice the raw string literal 17 00:00:55,490 --> 00:00:57,750 because of the \ character here, 18 00:00:57,750 --> 00:01:02,240 so \t is the escape sequence for a tab character, 19 00:01:02,240 --> 00:01:04,080 and we're saying that we are going 20 00:01:04,080 --> 00:01:08,950 to look for any sequence of one or more tab characters, 21 00:01:08,950 --> 00:01:11,570 and replace them with comma spaces. 22 00:01:11,570 --> 00:01:13,400 So, we have one tab character, 23 00:01:13,400 --> 00:01:15,060 then we have two tab characters, 24 00:01:15,060 --> 00:01:16,860 then we have three tab characters. 25 00:01:16,860 --> 00:01:18,990 And when we execute that, you can see now, 26 00:01:18,990 --> 00:01:23,080 we have a uniformly formatted comma delimited list 27 00:01:23,080 --> 00:01:26,860 with comma spaces separating each value 28 00:01:26,860 --> 00:01:28,713 in the string result. 29 00:01:29,870 --> 00:01:31,670 Now for the other exercise here, 30 00:01:31,670 --> 00:01:33,540 let's go ahead and reveal the answer. 31 00:01:33,540 --> 00:01:37,310 So again, we're splitting on one or more 32 00:01:37,310 --> 00:01:41,498 of the $ characters, so \$ 33 00:01:41,498 --> 00:01:46,498 because $ is a regular expression metacharacter. 34 00:01:46,860 --> 00:01:49,890 That was one of the characters that was listed previously 35 00:01:49,890 --> 00:01:52,450 in the metacharacters list that we showed you 36 00:01:52,450 --> 00:01:53,570 towards the beginning 37 00:01:53,570 --> 00:01:56,550 of the regular expressions presentation. 38 00:01:56,550 --> 00:02:00,740 And here again, + means one or more, so we have one $, 39 00:02:00,740 --> 00:02:03,700 and we have two $, so when we split that 40 00:02:03,700 --> 00:02:06,800 we get '123', 'Main', and 'Street', 41 00:02:06,800 --> 00:02:10,043 as three separate strings in the resulting list.