Course of Raku / Regexes and grammars / Regexes / Literals and character classes / Exercises

A letter or digit

Problem

A single character class can combine more than one range. Write a class that matches one character that is either a lowercase letter or a digit, and use it to find the first such character in the string ' @x7' (which starts with spaces and an @). Print the match.

Do not use a predefined class like \w — write the ranges yourself.

Example

The program prints:

「x」

Solution

See the solution

Course navigation

Solution: Match a phrase   |   Solution: A letter or digit