Course of Raku / Addendum 🆕 / Types and text machines / Regexes and grammars / Exercises

Validate identifiers

Problem

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.

Example

The program prints:

count: valid
total2: valid
2fast: invalid
my-var: invalid
_hidden: valid

Solution

See the solution

Course navigation

Solution: Normalise whitespace   |   Solution: Validate identifiers