1 00:00:00,460 --> 00:00:04,830 You can exclude any character or characters from a match. 2 00:00:04,830 --> 00:00:09,480 This can be useful for matching text between the limiters. 3 00:00:09,480 --> 00:00:12,481 For comma separated values, for example, 4 00:00:12,481 --> 00:00:18,006 we could match any character that is not a comma, to pull the limited values out. 5 00:00:18,006 --> 00:00:21,640 To match any character except a target character, 6 00:00:21,640 --> 00:00:25,970 we use a character set that starts with a carat. 7 00:00:25,970 --> 00:00:30,900 For example, to match any character except an @ symbol, 8 00:00:30,900 --> 00:00:35,350 you can put an @ symbol next to a carat in a character set. 9 00:00:36,650 --> 00:00:40,430 Add a dot to that to exclude dots from what is matched. 10 00:00:41,560 --> 00:00:43,100 Let's try this out. 11 00:00:43,100 --> 00:00:46,720 I cleared both windows so that we can start with a new example. 12 00:00:46,720 --> 00:00:53,358 Let's put an email address in as a test, say, toy@boat.com. 13 00:00:53,358 --> 00:00:59,840 Now I'll match any character that is not an @ symbol, not at. 14 00:01:01,170 --> 00:01:04,680 I'll put square brackets with a carat and an @ symbol. 15 00:01:06,050 --> 00:01:10,480 This striping means that each character is a separate, complete match for 16 00:01:10,480 --> 00:01:12,070 our expression. 17 00:01:12,070 --> 00:01:15,691 Every character except for the @ symbol, that is. 18 00:01:15,691 --> 00:01:19,909 If we want to match more than just one character with our expression, 19 00:01:19,909 --> 00:01:21,080 what should we do? 20 00:01:21,080 --> 00:01:22,470 Do you remember? 21 00:01:23,940 --> 00:01:27,985 One way would be to put a plus after it. 22 00:01:27,985 --> 00:01:30,510 Now we have two complete matches. 23 00:01:30,510 --> 00:01:35,290 The parser found three characters that were not @ symbols, 24 00:01:35,290 --> 00:01:37,620 then it found an @ symbol. 25 00:01:37,620 --> 00:01:41,860 So toy is the first match for this expression. 26 00:01:41,860 --> 00:01:46,631 After the @ symbol it found boat.com was a repeated string of 27 00:01:46,631 --> 00:01:50,360 characters that weren't assembled. 28 00:01:50,360 --> 00:01:58,550 If I put a dot in the set, You see the string has three complete matches. 29 00:01:58,550 --> 00:02:01,710 There are a couple of gotchas I want to point out here. 30 00:02:01,710 --> 00:02:07,280 Notice that a dot inside a set behaves differently than a dot outside a set. 31 00:02:08,310 --> 00:02:10,383 Inside it's a little dot, 32 00:02:10,383 --> 00:02:15,536 while outside it's a special character that matches everything. 33 00:02:15,536 --> 00:02:20,480 This can take some getting used to, but just remember, context matters. 34 00:02:21,830 --> 00:02:26,001 Next think about what would happen if I removed the + and 35 00:02:26,001 --> 00:02:28,590 put an m before the character set. 36 00:02:30,480 --> 00:02:34,150 Do you think it will match the m at the end of the string? 37 00:02:34,150 --> 00:02:37,520 Because m isn't followed by an @ or a dot. 38 00:02:41,660 --> 00:02:44,810 Turns out, the m is not matched. 39 00:02:44,810 --> 00:02:49,720 This is because the m isn't followed by any character at all. 40 00:02:49,720 --> 00:02:55,820 The character set is telling the parser that m must be followed by a character. 41 00:02:55,820 --> 00:02:59,760 It just can't be an @ symbol or a dot. 42 00:02:59,760 --> 00:03:05,390 So if I put a character here, say a %, we have a match. 43 00:03:07,030 --> 00:03:11,830 Regular expressions include characters, which are the opposite of the digit, 44 00:03:11,830 --> 00:03:15,880 word and whitespace characters that we learned earlier. 45 00:03:15,880 --> 00:03:19,552 If you capitalize any of them, you get the inverse. 46 00:03:19,552 --> 00:03:22,358 So, \D, for example, 47 00:03:22,358 --> 00:03:27,178 matches any character that is not a digit. 48 00:03:27,178 --> 00:03:32,601 For example, if I erase the regex, And 49 00:03:32,601 --> 00:03:37,122 put a \W, the @ symbol and the dot are matched, 50 00:03:37,122 --> 00:03:41,690 because they're not word characters. 51 00:03:41,690 --> 00:03:43,916 If I put a capital D instead, 52 00:03:43,916 --> 00:03:50,160 each character is matched because none of them are numerals. 53 00:03:50,160 --> 00:03:52,630 Check the teacher's notes for additional practice.