1 00:00:00,150 --> 00:00:00,769 Well 2 00:00:00,899 --> 00:00:01,169 back. 3 00:00:01,179 --> 00:00:05,929 So let me walk you through a few more operations by making use of the split function 4 00:00:06,150 --> 00:00:09,199 as well as some good old indexing. So 5 00:00:09,689 --> 00:00:15,310 I have on my screen two notes, I have an email address and then also a URL. 6 00:00:15,380 --> 00:00:16,729 Now looking at the email address, 7 00:00:16,739 --> 00:00:20,049 what if we wanted to extract the domain specifically? 8 00:00:20,059 --> 00:00:20,489 So 9 00:00:20,760 --> 00:00:22,729 we wanted to extract lab 10 00:00:23,170 --> 00:00:25,620 cyber.com and just get rid of the admin 11 00:00:25,829 --> 00:00:26,180 at. 12 00:00:26,340 --> 00:00:28,559 How are we going to do this? Well, first of all, 13 00:00:28,950 --> 00:00:32,500 let's assign a variable email to be 14 00:00:32,740 --> 00:00:33,500 admin at 15 00:00:33,619 --> 00:00:33,909 Lab 16 00:00:34,500 --> 00:00:35,979 saber.com. 17 00:00:36,500 --> 00:00:37,099 OK? 18 00:00:37,479 --> 00:00:37,939 So 19 00:00:38,810 --> 00:00:40,770 what I'll do right now is I'm going to create 20 00:00:40,779 --> 00:00:44,130 another variable that will now hold what we're looking for. 21 00:00:44,139 --> 00:00:45,790 So I'm going to call that one domain 22 00:00:46,779 --> 00:00:48,849 and now this is where the magic happens. OK? 23 00:00:49,159 --> 00:00:51,080 We want to split 24 00:00:52,830 --> 00:00:58,049 our string, we want to separate admin from lab cyber.com, right? So 25 00:00:58,310 --> 00:01:02,500 in between admin and lab cyber.com is what is the at symbol? So 26 00:01:02,720 --> 00:01:04,410 I'm going to say email 27 00:01:04,930 --> 00:01:06,580 and now split 28 00:01:07,019 --> 00:01:09,870 and now in brackets, what, where are we going to split from? 29 00:01:09,879 --> 00:01:11,410 We're gonna split from the 30 00:01:11,589 --> 00:01:12,010 ATY. 31 00:01:13,230 --> 00:01:13,809 OK. 32 00:01:14,419 --> 00:01:18,680 And now because we're looking for the second element 33 00:01:18,819 --> 00:01:24,400 when you split admin at lala.com from the ad one part will be admin, 34 00:01:24,410 --> 00:01:26,190 the other part will be labs.com, right? 35 00:01:26,199 --> 00:01:32,809 So we want to go with the second element and that's going to be 11 will stand for Lab 36 00:01:33,260 --> 00:01:34,110 cyber.com. 37 00:01:34,489 --> 00:01:37,319 And now all we have to do is to simply print 38 00:01:38,040 --> 00:01:38,050 a 39 00:01:38,150 --> 00:01:39,110 domain. 40 00:01:41,040 --> 00:01:49,120 And if I run the program there, it is Lab cyber.com. If I changed 1 to 0, instead 41 00:01:49,269 --> 00:01:53,129 this will not represent the first element which is going to be admin. 42 00:01:53,300 --> 00:01:57,569 So if I run the program again, right now, you can see it has changed to admin. 43 00:01:57,870 --> 00:01:58,430 So 44 00:01:58,559 --> 00:02:01,500 whenever you're trying to split a string into two, 45 00:02:02,250 --> 00:02:04,260 using the split function, 46 00:02:04,370 --> 00:02:08,649 first of all, you want to indicate OK, where do you want to begin the split from? 47 00:02:08,679 --> 00:02:11,270 In this case right now, we said from the add symbol. 48 00:02:11,449 --> 00:02:13,039 So right down at the middle 49 00:02:13,199 --> 00:02:18,679 on the left will be the index value of zero on the right will be the index value of one. 50 00:02:18,850 --> 00:02:22,050 And since we are looking for the domain specifically, 51 00:02:22,220 --> 00:02:24,240 we change 0 to 1, 52 00:02:24,399 --> 00:02:25,279 we run again 53 00:02:25,610 --> 00:02:27,330 and there you go. We have lab 54 00:02:27,639 --> 00:02:29,550 cyber.com. 55 00:02:29,559 --> 00:02:35,149 Now one of the second example in here, the URL, what exactly are we looking for here? 56 00:02:35,630 --> 00:02:41,490 Let's say we wanted to extract the actual file itself. 57 00:02:41,800 --> 00:02:45,020 So we're not interested in the whole HTTPS 58 00:02:45,279 --> 00:02:48,860 lab.com/path/so 59 00:02:49,089 --> 00:02:56,330 all we're looking for is simply the file name. How can we extract file from this? 60 00:02:56,649 --> 00:02:57,250 So 61 00:02:57,389 --> 00:03:01,490 what I'm gonna do very simply is to say URL 62 00:03:02,220 --> 00:03:03,009 equals. 63 00:03:03,660 --> 00:03:06,559 And let me just grab this, 64 00:03:06,809 --> 00:03:08,350 let me just copy that 65 00:03:09,080 --> 00:03:10,470 and I'm going to paste it 66 00:03:11,059 --> 00:03:12,380 and there you go. OK? 67 00:03:12,759 --> 00:03:13,380 So 68 00:03:13,830 --> 00:03:14,279 again, 69 00:03:14,289 --> 00:03:15,970 I'm going to create a new variable that will 70 00:03:15,979 --> 00:03:17,919 now hold the value of what we're looking for. 71 00:03:17,929 --> 00:03:19,550 Let's call this one, the file under the 72 00:03:19,789 --> 00:03:20,339 name 73 00:03:20,710 --> 00:03:22,970 will now be equal to 74 00:03:24,389 --> 00:03:28,350 URL, right? And now dot split 75 00:03:28,580 --> 00:03:31,130 and now check this out 76 00:03:31,479 --> 00:03:34,759 looking at the URL. OK. This full URL. 77 00:03:34,910 --> 00:03:36,059 What do you think? 78 00:03:36,070 --> 00:03:41,020 What symbol do you think we could use to split the string into multiple parts? 79 00:03:41,770 --> 00:03:47,009 Yep, it should be obvious it's going to be the forward slash, right? 80 00:03:47,190 --> 00:03:49,990 Because you can see right there. It's everywhere. 81 00:03:50,250 --> 00:03:52,839 So we're gonna split our string, we're gonna split our raw 82 00:03:53,210 --> 00:03:54,660 using the forward slash. 83 00:03:55,220 --> 00:03:59,550 And now how can we target the file? 84 00:04:00,199 --> 00:04:03,380 Do you remember negative indexing 85 00:04:03,860 --> 00:04:07,820 where we start from the end of our string? 86 00:04:07,990 --> 00:04:10,919 So in this case right now, what are we, what are we looking for? 87 00:04:10,929 --> 00:04:14,679 We're looking for the very first element from the end 88 00:04:14,809 --> 00:04:19,760 and now that will be negative. What negative one? 89 00:04:20,059 --> 00:04:25,359 So it's gonna start from file, it's gonna start from right to the left, right. So now 90 00:04:25,549 --> 00:04:27,049 all we have to do 91 00:04:27,250 --> 00:04:28,880 is to simply print 92 00:04:29,279 --> 00:04:31,320 the file 93 00:04:31,670 --> 00:04:33,320 underscore name 94 00:04:34,059 --> 00:04:35,089 and they should do the trick. 95 00:04:35,100 --> 00:04:39,519 Let's go ahead and run the program and there you go, we have the file name. 96 00:04:39,660 --> 00:04:44,119 So by making use of the split function and also a negative indexing, 97 00:04:44,130 --> 00:04:48,600 we were able to specifically target the file name. 98 00:04:48,609 --> 00:04:51,239 Let me give you one more example. 99 00:04:51,630 --> 00:04:57,399 And here we're going to extract some strings without using the split function. 100 00:04:57,410 --> 00:05:00,440 We're just going to use the index values. So 101 00:05:01,309 --> 00:05:03,769 let me provide the email address again 102 00:05:04,130 --> 00:05:05,959 and I'm going to say admin 103 00:05:06,109 --> 00:05:06,859 at Lab 104 00:05:07,269 --> 00:05:08,690 cyber.com. 105 00:05:09,649 --> 00:05:16,369 And OK, so what if we wanted to extract both the username and the domain? 106 00:05:16,920 --> 00:05:18,320 So we want to extract the username, 107 00:05:18,329 --> 00:05:21,309 which is admin and then the domain which is labs.com. 108 00:05:21,320 --> 00:05:24,470 How do you think we can do this? Well, first of all, 109 00:05:24,869 --> 00:05:28,130 I can say my username is going to be equal to 110 00:05:28,420 --> 00:05:29,390 email. 111 00:05:29,640 --> 00:05:34,510 And now remember how the indexes work when you have your starts and then the end. 112 00:05:34,829 --> 00:05:38,660 So we want to start from the very beginning of our string. 113 00:05:39,070 --> 00:05:41,190 So we're gonna say colon, 114 00:05:41,339 --> 00:05:43,739 we're gonna leave the left side blank because 115 00:05:43,750 --> 00:05:45,089 we're gonna start from the very beginning. 116 00:05:45,450 --> 00:05:47,489 And now let us see 117 00:05:47,700 --> 00:05:51,070 A is going to be uh index number is zero, right? 118 00:05:51,079 --> 00:05:58,769 So A is zero, D is one, M is two, I is three, N is four and of course, the at symbol is five. 119 00:05:58,779 --> 00:05:59,089 So 120 00:05:59,750 --> 00:06:02,130 I'm gonna say over here right now five. 121 00:06:02,690 --> 00:06:03,329 OK? 122 00:06:03,619 --> 00:06:05,890 And then I can say domain 123 00:06:06,100 --> 00:06:07,089 equals 124 00:06:08,000 --> 00:06:10,739 email. And now inside 125 00:06:10,959 --> 00:06:14,899 we want to start from what the sixth index which is gonna be L 126 00:06:15,880 --> 00:06:17,619 call on and then leave 127 00:06:17,760 --> 00:06:20,640 that blank. Because we, we're going all the way to the end of the string 128 00:06:20,940 --> 00:06:25,359 and now this should work. So all we got to do is to say print 129 00:06:25,839 --> 00:06:29,079 and now in here, let's say username. 130 00:06:29,750 --> 00:06:32,579 OK? And then comma username 131 00:06:33,380 --> 00:06:35,000 and then print 132 00:06:35,209 --> 00:06:37,079 brackets colon 133 00:06:37,899 --> 00:06:39,489 uh domain. 134 00:06:39,959 --> 00:06:40,959 OK. 135 00:06:41,519 --> 00:06:44,269 Comma domain. 136 00:06:45,290 --> 00:06:48,630 And there you go, let's run the program and there it is. 137 00:06:48,640 --> 00:06:50,450 Username is Admin Domain is lab 138 00:06:50,630 --> 00:06:53,230 cyber.com. Yay. 139 00:06:54,149 --> 00:06:55,109 But hold up 140 00:06:55,799 --> 00:06:56,809 just a minute 141 00:06:57,059 --> 00:06:58,829 before you pop the champagne. 142 00:06:59,130 --> 00:07:01,660 Let's run another test. OK. 143 00:07:01,670 --> 00:07:06,619 I'm gonna change admin here to, I don't know, let's say Alex, for example, 144 00:07:07,399 --> 00:07:08,980 never on the program. 145 00:07:13,239 --> 00:07:14,559 We do have a 146 00:07:14,850 --> 00:07:19,500 problem. You can see right now that the program has malfunctioned, 147 00:07:19,799 --> 00:07:22,309 it's no longer working properly 148 00:07:22,459 --> 00:07:24,690 instead of username, Alex, we have 149 00:07:24,910 --> 00:07:25,589 Alex at 150 00:07:25,809 --> 00:07:27,679 and instead of lab cyber.com, we have a 151 00:07:28,149 --> 00:07:29,269 cyber.com. 152 00:07:29,459 --> 00:07:31,100 What is going on here? 153 00:07:31,630 --> 00:07:32,239 See 154 00:07:32,700 --> 00:07:37,059 by trying to extract our strings by being very specific 155 00:07:37,070 --> 00:07:39,940 with the index values that we want to target. 156 00:07:40,880 --> 00:07:43,470 The program is going to rely very heavily 157 00:07:43,850 --> 00:07:47,160 on the actual email address, 158 00:07:47,309 --> 00:07:52,989 having the right number of characters, both before and after the at 159 00:07:53,109 --> 00:07:54,130 symbol. 160 00:07:54,929 --> 00:07:58,170 So it's heavily dependent on that, but we don't want that. 161 00:07:58,179 --> 00:08:00,309 We want the program to be flexible enough 162 00:08:00,559 --> 00:08:05,250 to always be able to accurately extract both the username and the domain 163 00:08:05,399 --> 00:08:09,790 regardless of how short or long the actual email address is. 164 00:08:10,079 --> 00:08:10,630 So 165 00:08:10,790 --> 00:08:13,350 what can we do? Well 166 00:08:14,230 --> 00:08:18,450 remember that the add symbol is where all the action is 167 00:08:18,670 --> 00:08:23,779 to the left of the add symbol is our username to its right is the domain. 168 00:08:23,790 --> 00:08:25,940 So we can target specifically 169 00:08:26,140 --> 00:08:31,160 the index value of the at symbol. 170 00:08:31,320 --> 00:08:32,849 And how do we do that 171 00:08:33,179 --> 00:08:34,960 for the username? Email? 172 00:08:35,130 --> 00:08:36,349 Right now 173 00:08:36,900 --> 00:08:37,369 again, 174 00:08:37,380 --> 00:08:39,849 we're gonna leave the first part of the column 175 00:08:39,859 --> 00:08:42,090 blank because we're starting from the very beginning, 176 00:08:42,099 --> 00:08:42,570 right? 177 00:08:43,030 --> 00:08:45,530 And now to target the actual 178 00:08:45,640 --> 00:08:48,210 at symbol, its index value, 179 00:08:48,489 --> 00:08:52,929 I'm gonna say email again and now dot index 180 00:08:53,330 --> 00:08:55,030 and now in brackets 181 00:08:55,659 --> 00:08:56,929 code the 182 00:08:57,070 --> 00:08:58,570 at symbol. 183 00:08:59,179 --> 00:09:02,750 So now I'm saying the username always begin from the 184 00:09:02,760 --> 00:09:04,700 from always start from the very beginning of the string 185 00:09:04,960 --> 00:09:09,739 and then end once you have reached the index value of the 186 00:09:09,859 --> 00:09:11,270 at symbol, 187 00:09:11,640 --> 00:09:15,150 likewise, we can do something very similar with the domain, 188 00:09:15,369 --> 00:09:17,039 we can say domain. 189 00:09:17,380 --> 00:09:21,179 OK, let's start from the beginning of in here email 190 00:09:21,380 --> 00:09:23,159 dot index. 191 00:09:23,520 --> 00:09:27,739 And now what are we targeting again? We're targeting the AD symbol. 192 00:09:28,130 --> 00:09:29,380 However, 193 00:09:29,669 --> 00:09:33,299 we specifically want to target the very first character, 194 00:09:33,309 --> 00:09:37,049 the very first index after the ad symbol. 195 00:09:37,059 --> 00:09:38,219 So what do you think we're gonna do? 196 00:09:38,510 --> 00:09:39,299 We 197 00:09:39,479 --> 00:09:42,580 the good people, we're gonna say plus one 198 00:09:43,250 --> 00:09:44,349 plus one. 199 00:09:44,669 --> 00:09:46,090 So now I said, OK, 200 00:09:46,260 --> 00:09:50,250 start from the index value of add but 201 00:09:50,590 --> 00:09:56,159 then add one to it. So it's gonna go to add and then add one. OK? Now Lab 202 00:09:56,989 --> 00:09:58,070 cyber.com. 203 00:09:58,309 --> 00:10:02,559 So now if I run the program, there you go. It works. Alex 204 00:10:02,840 --> 00:10:02,869 Lab 205 00:10:03,010 --> 00:10:03,869 cyber.com. 206 00:10:04,049 --> 00:10:05,609 If I change Alex 207 00:10:05,770 --> 00:10:07,950 back to admin 208 00:10:08,630 --> 00:10:11,130 and here on the program, you can see it works. 209 00:10:12,000 --> 00:10:15,739 In fact, let's try something completely different. OK. 210 00:10:15,849 --> 00:10:19,809 Let's say uh Jack Daniels 211 00:10:20,159 --> 00:10:21,830 at Super 212 00:10:22,210 --> 00:10:24,739 yahoo.com something weird, right? 213 00:10:24,940 --> 00:10:27,469 Let's run the program and there you go, 214 00:10:27,609 --> 00:10:30,940 Jack Daniels and then the Domain Super yahoo.com. 215 00:10:31,359 --> 00:10:36,510 So this is how to successfully and efficiently extract 216 00:10:36,520 --> 00:10:39,809 your strings without making use of the split function, 217 00:10:39,820 --> 00:10:40,869 we simply used 218 00:10:41,520 --> 00:10:42,669 the index values 219 00:10:42,780 --> 00:10:46,849 and we targeted specifically the index value of the A symbol. 220 00:10:46,859 --> 00:10:47,549 Because remember again, 221 00:10:47,559 --> 00:10:50,219 the at symbol is where all the action is to the left of 222 00:10:50,229 --> 00:10:53,559 the ad symbol is a username to its right is the domain. 223 00:10:53,570 --> 00:10:56,130 So I hope you enjoyed the video. Thank you for watching. 224 00:10:56,140 --> 00:10:57,780 I will see you in the next class.