Skip to content

str_replace() with function #5

@hadley

Description

@hadley

Something like

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions