I have a string that looks like this:
BA46_05-07-2019_rxn2_AAGAACATCCCTCTCC
I want to remove everything between rxn2
and BA46_
Desired end results:
BA46_rxn2_AAGAACATCCCTCTCC
How can I do this?
CodePudding user response:
gsub("BA46_[a-zA-Z0-9_-]*rxn2","BA46_rx2","BA46_05-07-2019_rxn2_AAGAACATCCCTCTCC")
CodePudding user response:
Try this
x <- "BA46_05-07-2019_rxn2_AAGAACATCCCTCTCC"
sub("_[0-9\\-]*_" , "_" , x)
- output
[1] "BA46_rxn2_AAGAACATCCCTCTCC"
CodePudding user response:
library(stringr)
str_remove(string, '\\d{2}\\-\\d{2}\\-\\d{4}\\_')
[1] "BA46_rxn2_AAGAACATCCCTCTCC"