I'm trying to create a RE for an exact match of a string that starts with at most two alphabetic characters and is followed by at most two numeric characters.
test <- function(x) {
valid_pattern <- "^[a-zA-Z]{,2}\\d{,2}$"
return(grepl(valid_pattern, x))
}
sapply(c("OX4", "sw33", "WJx9", "W392"), test)
I would like the above to return TRUE, TRUE, FALSE, FALSE. Currently, it returns TRUE for all. What am I missing?