Course of Raku / Regexes and grammars / Regexes / Captures / Named captures
Quiz — Captures
What does the following program print?
if 'ab12cd' ~~ / (\w+) (\d+) / {
say "$0 $1";
}| 0 | ab 12 |
| 1 | ab1 2 |
| 0 | ab12 cd |
| 0 | 12 ab |
The greedy \w+ matches word characters as far as it can
while still leaving at least one digit for \d+. It takes
ab1, and \d+ then matches the single remaining
digit 2. So $0 is ab1 and
$1 is 2.