regexprep.RdReplace string using regular expression.
regexprep(s, expr, repstr, ignorecase = FALSE, once = FALSE)Matches the regular expression against the string and replaces the first or all non-overlapping occurrences with the replacement string.
The syntax for regular expression has to be PERL-like.
String with substrings replaced.
The Matlab/Octave variant allows a character vector. This is not possible here as it would make the return value quite complicated.
s <- "bat cat can car COAT court cut ct CAT-scan"
pat <- 'c[aeiou]+t'
regexprep(s, pat, '---')
#> [1] "bat --- can car COAT court --- ct CAT-scan"
regexprep(s, pat, '---', once = TRUE)
#> [1] "bat --- can car COAT court cut ct CAT-scan"
regexprep(s, pat, '---', ignorecase = TRUE)
#> [1] "bat --- can car --- court --- ct ----scan"