library(stringr)
string <- "path/stack/over_flow/Pedro_account"
str_extract(string, "(?<=/)[^/]{2}(?=[^/]*$)")