fn <- function(path) {
pattern <- gsub(":([^/]+)", "(\\\\w+)", path)
paste0("^", pattern, "$")
}
path_to_pattern <- as_path_to_pattern(fn)
path <- "/dashboard/profile/:user_id"
pattern <- path_to_pattern(path) # "^/dashboard/profile/(\w+)$"
Run the code above in your browser using DataLab