Skip to content

Instantly share code, notes, and snippets.

@apoorv74
Created January 11, 2018 08:03
Show Gist options
  • Save apoorv74/95ab15431468631e77d92b63750aac32 to your computer and use it in GitHub Desktop.
Save apoorv74/95ab15431468631e77d92b63750aac32 to your computer and use it in GitHub Desktop.
Gsub over a map
convert <- function(x) {
map <- c("\\[:alpha:\\]" = "a-zA-Z", "\\[:digit:\\]" = "0-9")
for (i in seq_along(map)) {
x <- gsub(names(map)[[i]], map[[i]], x)
}
x
}
convert("[[:alpha:]](?:(?:[[:digit:]]){1,2}(?:[[:alpha:]]){1,2})(?:(?:[[:digit:]]){6,7})")
#> [1] "[a-zA-Z](?:(?:[0-9]){1,2}(?:[a-zA-Z]){1,2})(?:(?:[0-9]){6,7})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment