GROUPS & ALTERNATION
Alternation
The pipe | means OR: match this branch or that one.
The pipe means OR. cat|dog matches cat or dog. The engine tries branches left to right and takes the first one that works at the current position.
Alternation has the LOWEST precedence of any operator. ^cat|dog$ does not mean "a line that is cat or dog" - it means ^cat OR dog$. You need a group to contain it, which is the next lesson.
PRACTICE - 3 DRILLS 0/3 DONE
Match every cat and every dog.
/ /
the cat chased the dog
must match: "cat" "dog"
dog dog cat
must match: "dog" "dog" "cat"
birds only
must match nothing
Match yes, no or maybe.
/ /
yes / no / maybe
must match: "yes" "no" "maybe"
maybe yes
must match: "maybe" "yes"
absolutely
must match nothing
Match the extensions jpg, png and gif.
/ /
a.jpg b.png c.gif d.txt
must match: "jpg" "png" "gif"
logo.png
must match: "png"
notes.md
must match nothing