Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Matching Character Ranges1:58 with Joel Kraft
Learn match ranges of characters such as a-z, A-Z or 0-9.
Copy each set of test strings into regexpal. 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 characters like A to Z, or
a range of numbers like zero to nine in character sets.
Let's say instead of matching just these three characters for example,
you want to match any character in the alphabet.
This can be done by replacing the contents of the brackets with 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 characters.
To include all lower case letters, we can put another range right next to the first.
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
js these strings start with.
I'll just change one of these ts to a z.
It's still matched.
Now, I'll change it to a capital S, cool.
I'll change it back to a t.
I just wanna show you that you can use numerals the same way.
I'll create a new character set at the beginning of the expression,
followed by a space.
Inside I'll put 0 through 7.
All 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.
I'll replace it with a 9.
And it's unmatched.
Note, I can still enter individual characters I want to match in a set.
For example, let's say I want to match the letter a.
I can type it in the set and then use it on the first line.
Try some of the exercises in the teacher's notes for more practice.
Next, let's look at more concise ways to express common character sets.
You need to sign up for Treehouse in order to download course files.Sign up