Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Alternation1:26 with Joel Kraft
You learned about the concept of NOT in the last video. Regular expressions also support the idea of OR. We'll cover that here.
Copy both the Match and the Exclude set of test strings from each exercise below into regexpal. Using what you've learned so far, create a regular expression that will match all of the strings in the Match set and exclude the ones in the Exclude set.
farmhouse bighouse firehouse
It tells the parser to either match one pattern or another.
Instead of two pipe characters, though, it's just one.
I've cleared the regex from the last video.
I'll replace the email portion of this string, so I just have toy.
Then I'll add sale, steam, and tug underneath.
Now if I only want to match toy or sale,
I can type them both separated by a pipe character.
Notice how steam and tug are not matched.
This can help you get really specific about strings that may not follow
a common pattern.
To match tug, I could just add another pipe and follow it with tug.
What if we only want to match part of a string with alternation though?
For example, if I put a space boat on the end of each of these
strings, how can I match each whole string?
If I put a space at the end of the regex and boat, only tug is matched.
That's because the pipe character naturally groups the expressions that
In other words, I need to put a space boat after toy and sail too.
But there is a better way which I'll show you in the next video.
You need to sign up for Treehouse in order to download course files.Sign up