Skip to contents

Replace multiple text tokens with new text in provided string.

Usage

multi_replace_all(text, tbl, add_breaks = TRUE)

Arguments

text

A string vector to replace tokens in.

tbl

A two-column tibble with the token to replace and its corresponding new value.

add_breaks

A logical indicating whether to add \\b (word boundary) either side of each token.

Value

A character vector of strings with replaced tokens.

Details

The function

Examples

# Replace multiple tokens
text <- c("Hello world!", "Goodbye world!")
tbl <- data.frame(token = c("Hello", "world"), new = c("Hi", "universe"))
multi_replace_all(text, tbl)
#> [1] "Hi universe!"      "Goodbye universe!"
#> [1] "Hi universe!" "Goodbye universe!"