Created
January 11, 2018 08:03
-
-
Save apoorv74/95ab15431468631e77d92b63750aac32 to your computer and use it in GitHub Desktop.
Gsub over a map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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