Skip to contents

re_escape escapes all special characters in a string. This function is useful when you want to treat a string literally in a regular expression context, escaping characters that would otherwise be interpreted as special regex operators.

Usage

re_escape(pattern)

Arguments

pattern

A character vector where each element is a string in which special regex characters are to be escaped.

Value

A character vector of the same length as pattern.

Examples

re_escape("a[bc].*d?")
#> [1] "a\\[bc\\]\\.\\*d\\?"
re_escape(".^$|*+?{}[]()")
#> [1] "\\.\\^\\$\\|\\*\\+\\?\\{\\}\\[\\]\\(\\)"