R/str_to_regex.R

Defines functions str_to_regex

Documented in str_to_regex

#' Espace special characters in regex
#'
#' @param str A character vector
#' @return Initial vector with special
#'   characters escaped

str_to_regex <- function(str){

  special_characters <- c("^", "$", ".",
  "|", "?", "*",
  "+", "(", ")",
  "[", "]" ,"{", "}")

  return(
    mgsub(special_characters, paste0("\\", special_characters),
      str)
  )
}
linogaliana/tablelight documentation built on Jan. 29, 2021, 10:30 a.m.