regexprep | R Documentation |
Replace string using regular expression.
regexprep(s, expr, repstr, ignorecase = FALSE, once = FALSE)
s |
Single character string. |
expr |
Regular expression to be matched. |
repstr |
String that replaces the matched substring(s). |
ignorecase |
logical, whether to ignore case. |
once |
logical, shall only the first or all occurences be replaced. |
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.
gsub
s <- "bat cat can car COAT court cut ct CAT-scan"
pat <- 'c[aeiou]+t'
regexprep(s, pat, '---')
regexprep(s, pat, '---', once = TRUE)
regexprep(s, pat, '---', ignorecase = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.