Why regexp? IPv4 regexp

is_valid_ipv4_regex <- function(ip) {
  pattern <- "^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})(\\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})){3}$"
  grepl(pattern, ip)
}

is_valid_ipv4_regex(ip1)
## [1] TRUE
is_valid_ipv4_regex(ip2)
## [1] FALSE
is_valid_ipv4_regex(ip3)
## [1] TRUE