1 00:00:00,880 --> 00:00:04,800 You can exclude any character or characters from a match. 2 00:00:04,800 --> 00:00:08,740 This can be useful for matching text between delimiters. 3 00:00:08,740 --> 00:00:11,580 For comma separated values, for example, 4 00:00:11,580 --> 00:00:16,950 we could match any character that is not a comma to pull delimited values out. 5 00:00:16,950 --> 00:00:18,350 To match any character, 6 00:00:18,350 --> 00:00:23,240 except a target character, we'll use a character set that starts with caret. 7 00:00:23,240 --> 00:00:26,605 For example, to match any character except an @ symbol, 8 00:00:26,605 --> 00:00:30,660 you can put an @ symbol next to a caret in a character set. 9 00:00:30,660 --> 00:00:34,280 Add a dot to that to exclude dots from what's matched. 10 00:00:34,280 --> 00:00:35,540 Let's try it out. 11 00:00:35,540 --> 00:00:39,490 I cleared both windows out so we can start with a new example. 12 00:00:39,490 --> 00:00:42,560 Let's put an email address in as test. 13 00:00:42,560 --> 00:00:47,159 Say, toy@boat.com. 14 00:00:47,159 --> 00:00:51,068 Now I'll match any character that's not an @ symbol. 15 00:00:51,068 --> 00:00:57,320 I'll put square brackets with a caret and inside I'll put an @ symbol. 16 00:00:57,320 --> 00:01:01,110 The striping means that each character is a separate complete match for 17 00:01:01,110 --> 00:01:05,860 our expression, every character except the @ symbol that is. 18 00:01:05,860 --> 00:01:09,087 If we want to match more than one character with our expression, 19 00:01:09,087 --> 00:01:10,056 what should we do? 20 00:01:10,056 --> 00:01:11,540 Do you remember? 21 00:01:11,540 --> 00:01:14,850 One way would be to put a + sign after it. 22 00:01:14,850 --> 00:01:17,300 Now we have two complete matches. 23 00:01:17,300 --> 00:01:20,940 The parser found three characters that were not @ symbols. 24 00:01:20,940 --> 00:01:26,060 Then it found an @ symbol, so toy is the first match for this expression. 25 00:01:26,060 --> 00:01:27,439 After the @ symbol, 26 00:01:27,439 --> 00:01:33,590 it found boat.com was a repeated string of characters that weren't @ symbols. 27 00:01:33,590 --> 00:01:39,340 If I put a dot in the set, you see the string has three complete matches. 28 00:01:39,340 --> 00:01:42,530 There are a couple gotchas I want to point out here. 29 00:01:42,530 --> 00:01:48,270 Notice that a dot inside a set behaves differently than a dot outside a set. 30 00:01:48,270 --> 00:01:51,290 Inside, it's a literal dot, while outside, 31 00:01:51,290 --> 00:01:54,420 it's a special character that matches everything. 32 00:01:54,420 --> 00:01:59,260 This can take some getting used to, but just remember context matters. 33 00:01:59,260 --> 00:02:03,512 Next, think about what would happen if I remove the + and 34 00:02:03,512 --> 00:02:06,093 put an m before the character set. 35 00:02:06,093 --> 00:02:09,240 Do you think it will match the m at the end of the string, 36 00:02:09,240 --> 00:02:12,380 because m isn't followed by an @ or a dot? 37 00:02:12,380 --> 00:02:12,880 Let's find out. 38 00:02:15,218 --> 00:02:17,820 Turns out the m is not matched. 39 00:02:17,820 --> 00:02:22,360 This is because the m isn't followed by a character at all. 40 00:02:22,360 --> 00:02:27,380 The character set is telling the parser that m must be followed by a character, 41 00:02:27,380 --> 00:02:30,290 it just can't be an @ symbol or a dot. 42 00:02:30,290 --> 00:02:35,510 So if I put a character here, say a % sign, we have a match. 43 00:02:35,510 --> 00:02:39,870 Regular expressions include characters which are the opposite of the digit, 44 00:02:39,870 --> 00:02:43,320 word and whitespace characters we learned earlier. 45 00:02:43,320 --> 00:02:46,638 If you capitalize any of them, you get the inverse. 46 00:02:46,638 --> 00:02:52,530 So \D, for example, matches any character that is not a digit. 47 00:02:53,760 --> 00:02:57,965 For example, if I erase this regex and put a /W, 48 00:02:57,965 --> 00:03:04,280 the @ symbol and dot are matched because they are not word characters. 49 00:03:04,280 --> 00:03:10,980 If I put a D instead, each character is matched because none of them are numerals. 50 00:03:10,980 --> 00:03:13,280 Check the teacher's notes for additional practice.