gsub() to replace string patter globally advice??

I need some help to work on a string pattern search and replace it with a blank.
The patter of the string is
TCGA-4C-A93U-01A-11R-A39I-07 and I need to delete everything starting from 11R including the hyphen before 11R. I prepared this regexp to work on it. Am I missing something?

gsub("-[0-9]R-[a-z]-[0-9]*", "", DF) or

gsub("-[0-9]R-[A-z0-9]-[0-9]", "", DF)

Thank you!

I think this is what you want.

sub("-\\w{3}-\\w{4}-\\d{2}$", "", "TCGA-4C-A93U-01A-11R-A39I-07")
#> [1] "TCGA-4C-A93U-01A"

Created on 2020-05-13 by the reprex package (v0.3.0)

1 Like

Thanks you very much. It works.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.