| fgsub {textclean} | R Documentation |
This is a stripped down version of gsubfn from the gsubfn
package. It finds a regex match, and then uses a function to operate on
these matches and uses them to replace the original matches. Note that
the stringi packages is used for matching and extracting the regex
matches. For more powerful needs please see the gsubfn package.
fgsub(x, pattern, fun, ...)
x |
A character vector. |
pattern |
Character string to be matched in the given character vector. |
fun |
A function to operate on the extracted matches. |
... |
ignored. |
Returns a vector with the pattern replaced.
fgsub(
x = c(NA, 'df dft sdf', 'sd fdggg sd dfhhh d', 'ddd'),
pattern = "\\b\\w*([a-z])(\\1{2,})\\w*\\b",
fun = function(x) {paste0('<<', paste(rev(strsplit(x, '')[[1]]), collapse =''), '>>')}
)