R/escapeRegex.R

Defines functions escapeRegex

Documented in escapeRegex

#' escapeRegex
#' 
#' Escapes all symbols in a string which have a special meaning in regular
#' expressions.
#' 
#' 
#' @param x String or vector of strings that should be escaped.
#' @return The escaped strings.
#' @author Jan Philipp Dietrich
#' @seealso \code{\link[base]{grep}}
escapeRegex <- function(x) 
{
    return(gsub("([.|()\\^{}+$*?]|\\[|\\])", "\\\\\\1", x))
}

Try the magclass package in your browser

Any scripts or data that you put into this service are public.

magclass documentation built on July 9, 2023, 7:03 p.m.