Skip to contents

Given a character string, ensure this would function as a regular expression by escaping regex metacharacters which appear in the string.

Usage

escape_txt(txt)

Arguments

txt

The string which should be escaped so that it can function as a regular expression.

Value

The given string with regex metacharacters escaped.

Examples

escape_txt(".") # => "\."
#> [1] "\\."
escape_txt("ab[c]") # => "ab\[c\]"
#> [1] "ab\\[c\\]"
escape_txt("$30") # => "\$30"
#> [1] "\\$30"