Metacharacters

  • ., +, *, [, ], and ? are metacharacters and have special meanings.
  • . matches any character (except a newline):
# any string that contains an “a” followed by another character
str_view(c("a", "ab", "ae", "bd", "ea", "eab"), "a.")
## [2] │ <ab>
## [3] │ <ae>
## [6] │ e<ab>
# all the fruits that contain an “a”, followed by three letters,
# followed by an “e”:
str_view(fruit, "a...e")
##  [1] │ <apple>
##  [7] │ bl<ackbe>rry
## [48] │ mand<arine>
## [51] │ nect<arine>
## [62] │ pine<apple>
## [64] │ pomegr<anate>
## [70] │ r<aspbe>rry
## [73] │ sal<al be>rry