Exercise

Repetition

The rebus functions one_or_more(), zero_or_more() and optional() can be used to wrap parts of a regular expression to allow a pattern to match a variable number of times.

Take our vowels pattern from the last exercise. You can pass it to one_or_more() to create the pattern that matches "one or more vowels". Take a look with these interjections:

x <- c("ow", "ooh", "yeeeah!", "shh")
str_view(x, pattern = one_or_more(vowels))

You'll see we can match the single o in ow, the double o in ooh and the string of es followed by the a in yeeeah, but nothing in shh because there isn't a single vowel.

In contrast zero_or_more() will match even if there isn't an occurrence, try

str_view(x, pattern = zero_or_more(vowels))

Since both yeeeah and shh start without a vowel, they match "zero vowels", and since regular expressions are lazy, they look no further and return the start of the string as a match.

Instructions 1/2

undefined XP
  • 1

    Find boy_names that are only vowels, by combining one_or_more() with vowels. You will need to either specify START and END or use exactly().

  • 2
    • Create a negated_char_class() that matches anything but a vowel. (Note: negated_char_class(vowels) is not the right answer!)
    • Find boy_names that have no vowels, by combining exactly() and one_or_more() with not_vowels.