Course of Raku / Addendum 🆕 / Types and text machines / Regexes and grammars / Exercises
Validate identifiers
Problem
In many programming languages, a valid identifier starts with a
letter or underscore and continues with letters, digits, or underscores.
For count, total2, 2fast,
my-var, and _hidden, print whether each is a
valid identifier by that classic rule.
(Raku itself is more generous: my-var is a perfectly
valid Raku identifier. Check the solution page for that variant
too.)
Example
The program prints:
count: valid
total2: valid
2fast: invalid
my-var: invalid
_hidden: validSolution
Course navigation
← Solution: Normalise whitespace | Solution: Validate identifiers →