library(stringr)string <- "path/stack/over_flow/Pedro_account"str_extract(string, "(?<=/)[^/]{2}(?=[^/]*$)")
Standard input is empty
[1] "Pe"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!