s <- "1-343-43Hello_2_323.14_fdh-99H"
In R I want to use a regex to get the substring before the, say 2nd, underscore. How can this be done with one regex ? The alternative would be to split by '_' and then paste the first two - something along;
paste(sapply(strsplit(s, "_"),"[", 1:2), collapse = "_")
Gives:
[1] "1-343-43Hello_2"
But how can I make a regex expression to do the same ?