Course of Raku / Regexes and grammars / Regexes / Alternations / Alternation

Quiz — Grouping

What does the following program print?

say 'goodbye' ~~ / [ hello | good ] bye /;
1「goodbye」
0「good」
0「bye」
0False

The square brackets group the alternation hello | good without capturing, so the pattern means “hello or good, then bye”. In goodbye the good alternative matches and is followed by bye, giving 「goodbye」.

Course navigation

Alternation   |   Longest token and first match