Course of Raku / Regexes and grammars / Regexes / Alternations / Exercises / Word or digit
Solution: Word or digit
Here is a possible solution to the task.
Code
say 'item 5' ~~ / cat | \d /;🦋 You can find the source code in the file yes-or-no.raku.
Output
「5」Comments
The alternation mixes a literal,
cat, with a character class,\d. The pattern matches whichever alternative is found first in the string.There is no
catinitem 5, but there is a digit, so\dmatches the5.
Course navigation
← Word or digit | A size word →