Escaping metacharacters

  • all of the metacharacters: .^$\|*+?{}[]()
  • to match a metacharacter you need to escape with \
  • regexes are represented by strings that also use \ as escape symbol, so to escape a dot . for example, you need to use "\\."
# To create the regular expression \., we need to use \\.
dot <- "\\."

# But the expression itself only contains one \
str_view(dot)
## [1] │ \.
# And this tells R to look for an explicit .
str_view(c("abc", "a.c", "bef"), "a\\.c")
## [2] │ <a.c>