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

  1. The alternation mixes a literal, cat, with a character class, \d. The pattern matches whichever alternative is found first in the string.

  2. There is no cat in item 5, but there is a digit, so \d matches the 5.

Course navigation

Word or digit   |   A size word