Course of Raku / Regexes and grammars / Regexes / Alternations / Longest token and first match

Quiz — Alternations

What does the following program print? Note the single bar |.

say 'download' ~~ / down | download /;
1「download」
0「down」
0「load」
0False

The single bar | uses longest-token matching: when more than one alternative matches at the same spot, the longest one wins. Even though down is written first and would match, | prefers the longer download. With || instead, down would have won.

Course navigation

Longest token and first match   |   Word or digit