Skip to contents

Escapes any characters that would have special meaning in a regular expression.

Usage

escapeRegex(string)

Arguments

string

string being operated on.

Value

The value of the string with any characters that would have special meaning in a regular expression escaped.

Details

escapeRegex will escape any characters that would have special meaning in a regular expression. For any string grep(regexpEscape(string), string) will always be true.

Note

Note that this function was copied literally from the Hmisc package (to prevent importing the entire package for one line of code).

Author

Charles Dupont
Department of Biostatistics
Vanderbilt University

Maintainer: Gjalt-Jorn Peters gjalt-jorn@bookmark.opens.science

Examples


string <- "this\\(system) {is} [full]."
escapeRegex(string)
#> [1] "this\\\\\\(system\\) \\{is\\} \\[full\\]\\."
# \dontshow{
if(!any(grep(escapeRegex(string), string))) {
  stop("function escapeRegex failed test")
}
# }