Character classes

  • Defined by []: match a set of characters
    • [abcd] matches “a”, “b”, “c”, or “d”.
  • Invert the match: start with ^:
    • [^abcd] matches anything except “a”, “b”, “c”, or “d”.
# words containing an “x” surrounded by vowels:
str_view(words, "[aeiou]x[aeiou]")
## [284] │ <exa>ct
## [285] │ <exa>mple
## [288] │ <exe>rcise
## [289] │ <exi>st
# words containing a “y” surrounded by consonants
str_view(words, "[^aeiou]y[^aeiou]")
## [836] │ <sys>tem
## [901] │ <typ>e