Character classes
A literal like /cat/ matches one exact sequence. A character class
matches any one character from a set instead. \d means "any digit" -
0-9 - and it stands for exactly one character, not a whole number; to
match "2026" you'd need four of them in a row (more on that next lesson).
You can also build your own class with square brackets: [aeiou] means "any
one of these vowels," and matches the first one it finds anywhere in the
string.
Your task: write hasDigit(str), true if str contains any digit
(\d), and hasVowel(str), true if str contains any vowel ([aeiou]).
You'll practice:
Matching any digit with \d
Matching a custom set of characters with [...]
Show a hint
Show solution
Related reading: The Core Toolkit →
Previous Next