Skip to contents

Wrapper function for string replacement using [stringr::str_replace_all()]

Usage

strReplaceAll(string, pattern, replacement)

Arguments

string

Input vector. Either a character vector, or something coercible to one.

pattern

Pattern to look for.

The default interpretation is a regular expression, as described in stringi::about_search_regex. Control options with regex().

For str_replace_all() this can also be a named vector (c(pattern1 = replacement1)), in order to perform multiple replacements in each element of string.

Match a fixed string (i.e. by comparing only bytes), using fixed(). This is fast, but approximate. Generally, for matching human text, you'll want coll() which respects character matching rules for the specified locale.

replacement

The replacement value, usually a single string, but it can be the a vector the same length as string or pattern. References of the form \1, \2, etc will be replaced with the contents of the respective matched group (created by ()).

Alternatively, supply a function, which will be called once for each match (from right to left) and its return value will be used to replace the match.

Examples

strReplaceAll('Hello, world!', '[aeiou]', 'X')
#> Error in strReplaceAll("Hello, world!", "[aeiou]", "X"): could not find function "strReplaceAll"