Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

regexprep

Replace string using regular expression


Description

Replace string using regular expression.

Usage

regexprep(s, expr, repstr, ignorecase = FALSE, once = FALSE)

Arguments

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.

Details

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.

Value

String with substrings replaced.

Note

The Matlab/Octave variant allows a character vector. This is not possible here as it would make the return value quite complicated.

See Also

Examples

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)

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.