Given this string:
DNS000001320_309.0/121.0_t0
How would I return everything before the second occurrence of \"_\"?
DNS0000
Personally, I hate regex, so luckily there's a way to do this without them, just by splitting the string:
> s <- "DNS000001320_309.0/121.0_t0"
> paste(strsplit(s,"_")[[1]][1:2],collapse = "_")
[1] "DNS000001320_309.0/121.0"
Although of course this assumes that there will always be at least 2 underscores in your string, so be careful if you vectorize this and that isn't the case.