Course of Raku / Regexes and grammars / Regexes / Adverbs / Exercises / Count the matches
Solution: Count the matches
Here is a possible solution to the task.
Code
say ('education' ~~ m:g/<[aeiou]>/).elems;🦋 You can find the source code in the file count-matches.raku.
Output
5Comments
The character class
<[aeiou]>matches one vowel, and the:gadverb returns every such match instead of just the first.The result behaves like a list, so
.elemscounts the matches: the five vowels ineducation(e, u, a, i, o).