fork download
  1. teststring <- c("ENSG00032423", "ENSG00032411234|ENSMUS000124124", "ENSMUS00068967832|ENSG00045345112",
  2. "ENSG00032411234|ENSG000865852297",
  3. "ENSMUS00068967832|ENSG00045345112|ENSR00072699324",
  4. "ENSMUS00068967832|ENSR000124124124|ENSG00045345112")
  5.  
  6. gsub(
  7. pattern = "(?:(?<![^|])|\\|(?=[^|]*$))(?!ENSG)[^|]*\\|?",
  8. replacement = "",
  9. x = teststring,
  10. perl=TRUE
  11. )
  12.  
Success #stdin #stdout 0.28s 41020KB
stdin
Standard input is empty
stdout
[1] "ENSG00032423"                     "ENSG00032411234"                 
[3] "ENSG00045345112"                  "ENSG00032411234|ENSG000865852297"
[5] "ENSG00045345112"                  "ENSG00045345112"