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
TrueComments
The
^anchor forces the match to begin at the start of the string, and\dthen requires that first character to be a digit.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 →