Hmisc (version 5.1-2)

escapeRegex: Escapes any characters that would have special meaning in a reqular expression.

Description

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

Usage

escapeRegex(string)
escapeBS(string)

Value

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

Arguments

string

string being operated on.

Author

Charles Dupont
Department of Biostatistics
Vanderbilt University

Details

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

escapeBS will escape any backslash \ in a string.

See Also

Examples

Run this code
string <- "this\\(system) {is} [full]."
escapeRegex(string)

escapeBS(string)

# \dontshow{
if(!any(grep(escapeRegex(string), string))) {
  stop("function escapeRegex failed test")
}

if(escapeBS(string) != "this\\\\(system) {is} [full].") {
  stop("function escapeBS failed test")
}
# }

Run the code above in your browser using DataLab