regmatches(x, m, invert = FALSE) regmatches(x, m, invert = FALSE) <- value
x | a character vector. |
m | an object returned by regexpr, gregexpr, or regexec. It must be the same length as x. Usually it is the result of of regexpr (or like function) operating on x. |
invert | a logical value. If TRUE, extract or replace the non-matched substrings of x. If FALSE, operate on the matches substrings. |
value | a character vector to replace the matched or non-matched substrings. It is replicated to the length of x, and its i'th} element is used for all replacements in the \code{i'th element of x. |
regmatches() | returns a character vector with matched or non-matched substrings if m is a character vector and invert is FALSE. Otherwise, it returns a list of character vectors with matched or non-matched substrings. |
regmatches()<- | returns the updated character vector, thus updating its first argument when called in the usual way as regmatches(x, m) <- v. |
x <- c("Arkansas", "Alabama", "Calabash", "Washington") pattern <- "[Aa][^a]*a" # sequences starting with A or a and continuing up to next a.regmatches(x, gregexpr(pattern, x)) regmatches(x, gregexpr(pattern, x), invert = TRUE)
regmatches(x, regexpr(pattern, x)) regmatches(x, regexpr(pattern, x), invert = TRUE)
tmp <- x regmatches(tmp, gregexpr(pattern, tmp)) <- paste0("<",seq_along(x),">") tmp