R/utils.R

Defines functions str_replace_all str_extract_all `%or%`

`%or%` <- function(x, y) {
  if (length(x) == 0) y else x
}

str_extract_all <- function(x, pattern, invert = FALSE) {
  regmatches(x, gregexpr(pattern, x, perl = TRUE), invert)[[1]]
}

str_replace_all <- function(x, pattern, replacement) {
  regex <- gregexpr(pattern, x, perl = TRUE)
  regmatches(x, regex)[[1]] <- replacement
  x
}
wurli/pedant documentation built on Jan. 30, 2025, 5:38 a.m.