我想在vec中找到pat1或pat2
vec <- c("(and) i.e.","(and) ie","(and)ie","and i.e.","and ie","and) i.e.") pat1 <- "\\(and) i\\.e\\." pat2 <- "\\(and) ie"
我尝试使用(pat1 | pat2)组合这两个模式
# combine the two patterns pat1or2 <- paste0("(",pat1,"|",pat2,")") # [1] "(\\(and) i\\.e\\.|\\(and) ie)" grep(pat1,vec,value=TRUE) # [1] "(and) i.e." grep(pat2,value=TRUE) # [1] "(and) ie" grep(pat1or2,value=TRUE) # character(0)
显然,我错过了一些东西,我无法发现它.
(尝试弄乱perl并修复,但那不是)
你能指出我在组合这两种模式时的错误吗?