I have a string and I wish to extract the code but I’m not quite able to re-create it, the code will change each time but the IDs part will always be the same
mycode
"IDs/5362E-C3A~16DFR-54RFFG"
What I’m looking to get;
mycode
"5362E-C3A"
My attempt, I tried to break it down into 3 parts, Ids, the code I need and the tilde and other waste bit of code then saying I want to keep the first instance inside of the brackets.
mycode = gsub("IDs/([A-9]+)~[A-9+]", "\\1", mycode)
>Solution :
Assuming you want everything in between the / and the ~, you could try the following regex replacement which uses an alternation:
x <- "IDs/5362E-C3A~16DFR-54RFFG"
output <- gsub(".*/|~.*", "", x)
output
[1] "5362E-C3A"