Course of Raku / Regexes and grammars / Regexes / Anchors / Exercises / Starts with

Solution: Starts with

Here is a possible solution to the task.

Code

say so '3 apples' ~~ /^ \d /;

🦋 You can find the source code in the file starts-with.raku.

Output

True

Comments

  1. The ^ anchor forces the match to begin at the start of the string, and \d then requires that first character to be a digit.

  2. Without the ^, the pattern would also succeed for a digit appearing anywhere later in the string, such as 'apples 3'.

Course navigation

Starts with   |   The whole string