re2_replace(string, pattern, replacement, parallel = FALSE, grain_size = 1e+05, ...)re2_replace_all(string, pattern, replacement, parallel = FALSE, grain_size = 1e+05, ...)
pattern
in string
with "rewrite"re2
re2_replace
, a character vector. For re2_replace_all
, a character vector with the number of replacements.
Replace the the first match or all matches of pattern
in string
with replacement
.
Within replacement
, backslash-escaped digits (\1 to \9) can be
used to insert text matching corresponding parenthesized group
from the pattern. \0 in replacement
refers to the entire matching
text.
Vectorised over strings, patterns and replacements.
regexp = re2("b+") re2_replace_all("yabba dabba doo", regexp,"d")[1] "yada dada doo" attr(,"count") [1] 2re2_replace("yabba dabba doo", "b+","d")[1] "yada dabba doo"pattern = "^[\\s]+|[\\s]+$" re2_replace_all(c(" abc "," this is "), pattern, "")[1] "abc" "this is" attr(,"count") [1] 2 2