Something like ```R str_replace <- function(x, pattern, replace, ...) { loc <- gregexpr(pattern, x, perl = TRUE) out <- lapply(seq_along(out), function(i) { match <- regmatches(x[[i]], loc[[i]]) transform(match, ...) }) regmatches(x, loc) <- out x } ```