user1320502 user1320502 - 1 year ago 133
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


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download