Reputation: 1560
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?
Upvotes: 1
Views: 56
Reputation: 4725
sub('(.*BA46_).*(rxn2.*)','\\1\\2', 'BA46_05-07-2019_rxn2_AAGAACATCCCTCTCC')
I would go with this because it
BA46_
and rxn2
once, thus reducing the room for errorUpvotes: 0
Reputation: 78917
library(stringr)
str_remove(string, '\\d{2}\\-\\d{2}\\-\\d{4}\\_')
[1] "BA46_rxn2_AAGAACATCCCTCTCC"
Upvotes: 0
Reputation: 4425
Try this
x <- "BA46_05-07-2019_rxn2_AAGAACATCCCTCTCC"
sub("_[0-9\\-]*_" , "_" , x)
[1] "BA46_rxn2_AAGAACATCCCTCTCC"
Upvotes: 0
Reputation: 1389
gsub("BA46_[a-zA-Z0-9_-]*rxn2","BA46_rx2","BA46_05-07-2019_rxn2_AAGAACATCCCTCTCC")
Upvotes: 2