Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Matching Character Ranges2:33 with Alena Holligan
Learn match ranges of characters such as a-z, A-Z or 0-9.
Copy each set of test strings into regex101. Using what you've learned so far, create a regular expression that will match all of the strings in the set.
bat cat data eat fast
1 a 2 a 3 a 4 a 5 a 8 a 9 b
8345 Gable 7238 Gable 2349 Table 8475 Cable 0994 Fable 1047 Zable
4849 4472 4901 40502 43470 40496
You can also match a range of letters, like A through Z, or
a range of numbers, like 0 through 9, in character sets.
Let's say, instead of the first set that matches just these three characters,
you want to match any letter in the alphabet.
This can be done by replacing the contents of the brackets.
We'll set A-Z.
This hyphen tells the parser to include all letters in the range from A to Z.
You can see below that only one of the strings is highlighted.
That's because we've only specified uppercase letters.
To include all lowercase letters,
you can put another range right next to the first, lowercase a-z.
So ranges are put right next to each other in the square brackets.
Notice all the strings are highlighted again.
That's because the ranges we just entered include the Ts and
the Js that these strings start with.
I'll just change one of these Ts to a Z.
It still matches.
Now I'll change it to a capital S.
Cool, it still matches.
I'm going to change it back to the t.
I also want to show you that you can use numerals in the same way.
I'll just create a new character set at the beginning of the expression.
In square brackets, followed by a space, I'm going to add 0 through 7.
All of our tests are unmatched now because the parser is looking for
the string to start with a numeral between 0 and 7.
I'll type a 2 on the second line, followed by a space, and it's matched again.
I'll replace it with a 9, and it's unmatched.
Note that I can still enter individual characters I want to match into the set.
For example, let's say that I want to match the letter a.
I can type that into the set and then use it in our first line.
Try some of the exercises in the teachers notes for more practice.
Next, we'll look at a more concise way to express common character sets.
You need to sign up for Treehouse in order to download course files.Sign up