I have these two vectors:
sample1 <- c(\".aaa\", \".aarp\", \".abb\", \".abbott\", \".abogado\")
sample2 <- c(\"try1.aarp\", \"www.tryagain.aaa\", \"25
We can paste the 'sample1' elements together, use that as the pattern argument in gsub, replace it with ''.
gsub(paste(sample1, collapse='|'), '', sample2)
#[1] "try1" "www.tryagain" "255.255.255.255" "onemoretry"
Or use mgsub
library(qdap)
mgsub(sample1, '', sample2)
#[1] "try1" "www.tryagain" "255.255.255.255" "onemoretry"