我想pat1
在pat2
vec
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, vec, value=TRUE)
# [1] "(and) ie"
grep(pat1or2, vec, value=TRUE)
# character(0)
显然,我遗漏了一些东西,我无法发现它。
(尝试弄乱 perl 并修复,但不是这样)
你能指出我在结合这两种模式时的错误吗?