R/regex.R

Defines functions escape

Documented in escape

#' Escape regex
#'
#' @param x character
#'
#' @return escaped version of x
#' @export
escape <- function(x) {
  pattern <- r"--((?=[-\[\]{}()\*\+\?\.\,\\\^\$\|\#]))--"
  gsub(pattern, r"(\\)", x, perl = TRUE)
}
colin-fraser/colinlib documentation built on Nov. 30, 2022, 11:10 p.m.