RegexOneLearn regular expressions with simple, interactive examples.
Lesson 14: It’s all conditional
As I mentioned before, it's always good to be precise, and that applies to coding, talking, and even regular expressions. For example, I wouldn't write a grocery list for someone to Buy more .* because I would have no idea what I could get back. Instead I would write Buy more milk or Buy more bread and in regular expressions, we can actually define these conditionals explicitly.
Specifically when using groups, you can use the | (logical OR, aka. the pipe) to denote different possible sets of characters. In the above example, I can write the pattern "Buy more (milk|bread|juice)" to match only the strings Buy more milk, Buy more bread, or Buy more juice. Like normal groups, you use any of the techniques we've learned so far in defining the different possibilities.
Go ahead and try and write a conditional pattern that matches only the lines with small fuzzy creatures below.
