From the course: Learning Regular Expressions
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Alternation metacharacters - Regular Expressions Tutorial
From the course: Learning Regular Expressions
Alternation metacharacters
- [Narrator] In this movie we're going to learn to write regular expressions that use alternation. To do that we'll need to learn about the alternation metacharacter, which is just an upright bar or pipe. It'll depend on your keyboard layout, but it's often located on the right side, above the return key. You can think of this character as being an OR operator. Match either the expression on the left, or match the expression on the right. Now, they are ordered so the left most expression gets precedent. It'll try the first one. If it's not a match, then it'll proceed to the second one. If it is a match, well then it'll go ahead and just use that match. Multiple choices can be daisy-chained together. You can use those parentheses that we use to create groups so that you can group the alternation expressions and keep them distinct from the rest of the expression. Let's see some examples. If I have apple, and then…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.