user1320502 user1320502 - 7 months ago 63
R Question

regex, extract string between /

If I have these strings:

mystrings <- c("X2/D2/F4",

How can I extract
. These characters are between the
and after the first character within the

I would like to do this in a vectorized fashion and add the new column with
if possible with which I am familiar.

I think this regex gets me somewhere near all the characters within



as.numeric(gsub("^.*D([0-9]+).*$", "\\1", mystrings))