Substitute regular expressions in a string with another string.
Arguments
- data
character vector to substitute
- pattern
regular expression to match
- replacement
replacement text to use
- global
substitute all occurrences
- options
option flags
- ...
options passed to sub or gsub
See also
regexp
Section "Perl-like Regular Expressions" for a
discussion of the supported options
Examples
string <- c("this is a Test", "string")
re_substitutes(string, "test", "not a test", options = "insensitive")
#> [1] "this is a not a test" "string"
re_substitutes(string, "i", "x", global = TRUE)
#> [1] "thxs xs a Test" "strxng"
re_substitutes(string, "(test)", "not a \\1", options = "insensitive")
#> [1] "this is a not a Test" "string"