1 00:00:00,000 --> 00:00:05,320 A regular expression wildcard matches more than one character in a string. 2 00:00:05,320 --> 00:00:09,773 While we've been using character sets to match one than one character, 3 00:00:09,773 --> 00:00:12,991 there are shorter ways to match some of these cases. 4 00:00:12,991 --> 00:00:17,809 For example, instead of using 0 through 5 00:00:17,809 --> 00:00:22,221 9 to match any numeral, use the \d. 6 00:00:22,221 --> 00:00:25,856 The backslash is found often in regular expressions, but 7 00:00:25,856 --> 00:00:29,431 its meaning can differ, according to where it's used. 8 00:00:29,431 --> 00:00:33,362 Usually it's a way to say that the character that follows has a special 9 00:00:33,362 --> 00:00:33,969 meaning. 10 00:00:33,969 --> 00:00:38,849 In this case, it means that the d Isn't the letter d, 11 00:00:38,849 --> 00:00:43,091 but a special instruction to match a numeral. 12 00:00:43,091 --> 00:00:48,392 And even though there are two characters there, a backslash and 13 00:00:48,392 --> 00:00:52,629 a d, the parser treats this as a single character. 14 00:00:52,629 --> 00:01:00,623 To match all alphanumeric characters as well as an underscore, use \w. 15 00:01:00,623 --> 00:01:05,440 This can be handy for matching what's known as word characters. 16 00:01:05,440 --> 00:01:10,218 The reason underscore is included is that it's often used to space words 17 00:01:10,218 --> 00:01:13,988 out that can't actually have a space character in them. 18 00:01:13,988 --> 00:01:19,128 For example, some file systems won't let you use spaces in file names, 19 00:01:19,128 --> 00:01:23,524 so it's become common practice to use underscores instead. 20 00:01:23,524 --> 00:01:28,544 To match whitespace characters, you can use \s. 21 00:01:28,544 --> 00:01:33,397 In addition to the space, this wildcard includes other kinds 22 00:01:33,397 --> 00:01:37,612 of whitespace, a tab and a few kinds of line returns. 23 00:01:37,612 --> 00:01:40,358 If you want to know more about these special characters, 24 00:01:40,358 --> 00:01:41,796 check the Teacher's Notes. 25 00:01:41,796 --> 00:01:47,386 But for now, just think of the \s as a way to match whitespace, 26 00:01:47,386 --> 00:01:50,880 such as spaces, tabs, and new lines. 27 00:01:50,880 --> 00:01:55,320 Also, the period or dot matches any character. 28 00:01:55,320 --> 00:01:58,049 Let's try some of these out. 29 00:01:58,049 --> 00:02:06,930 Let's use a digit character shorthand in place of the first set, \d. 30 00:02:06,930 --> 00:02:12,422 Now any digit will be matched, but we lost the match we had for the letter a. 31 00:02:12,422 --> 00:02:18,462 We could match that by using a word shorthand, like this. 32 00:02:18,462 --> 00:02:22,617 Now any letter or digit will match. 33 00:02:22,617 --> 00:02:28,620 I'll change this first line to use a capital A, and it still matches. 34 00:02:28,620 --> 00:02:33,713 Note that an underscore will also match. 35 00:02:33,713 --> 00:02:39,131 Often when you're composing regex, you'll want to control what you include though. 36 00:02:39,131 --> 00:02:43,677 While the shorthand will often work, you might find yourself going with 37 00:02:43,677 --> 00:02:46,668 something more limiting, like we had before. 38 00:02:48,167 --> 00:02:55,119 We'll use \da, but we'll put these in a character set. 39 00:02:55,119 --> 00:02:59,124 Now the top string is no longer matched because it's an underscore. 40 00:02:59,124 --> 00:03:03,441 But if I change it back to an a, the first two lines are matched. 41 00:03:03,441 --> 00:03:08,707 I'll replace this space with a \s. 42 00:03:08,707 --> 00:03:13,654 Now notice, if I add an 8 and then a space, 43 00:03:13,654 --> 00:03:18,464 and then change the second space to a tab, 44 00:03:18,464 --> 00:03:21,633 the string still matches. 45 00:03:21,633 --> 00:03:26,565 I'll add a 3 to the next line, And 46 00:03:26,565 --> 00:03:31,121 instead of a space, I'll create a new line by typing Enter. 47 00:03:31,121 --> 00:03:33,562 See how the color carries over? 48 00:03:33,562 --> 00:03:36,557 So these two lines are one match now. 49 00:03:36,557 --> 00:03:38,411 Let's use the dot. 50 00:03:38,411 --> 00:03:41,067 I'll replace the s with a dot. 51 00:03:43,249 --> 00:03:46,774 All the same matches are still there because the dot will 52 00:03:46,774 --> 00:03:48,576 match any character at all. 53 00:03:48,576 --> 00:03:53,305 Let's change one of these s's to be an exclamation point, for example. 54 00:03:56,457 --> 00:04:00,452 It's a match, or maybe a dollar sign. 55 00:04:00,452 --> 00:04:04,789 As you can see, the dot is a powerful character in regex. 56 00:04:04,789 --> 00:04:07,979 You'll see it used in a lot of examples around the web. 57 00:04:07,979 --> 00:04:12,724 Remember that the question mark matches zero or one character. 58 00:04:12,724 --> 00:04:16,302 In other words, the character is optional. 59 00:04:16,302 --> 00:04:20,031 I'll show you another example where you might use this in a new tab. 60 00:04:23,349 --> 00:04:27,205 You could use the question mark to match both the American and 61 00:04:27,205 --> 00:04:30,315 the British spellings of the word, like color. 62 00:04:41,823 --> 00:04:44,665 Check the notes for some additional practice. 63 00:04:44,665 --> 00:04:49,640 In the next video, I'll show you how to match repeating characters.