更新时间:2023-02-21 18:55:43
我不知道 stringr 提供的函数是否以及如何实现,但您也可以使用 base regexpr
和 substring
:
I do not know whether and how this is possible with functions provided by stringr but you can also use base regexpr
and substring
:
pattern <- paste0("(?<=", left.border, ")[a-z]+(?=", right.border, ")")
# "(?<=nana)[a-z]+(?=baba)"
rx <- regexpr(pattern, text=my.string, perl=TRUE)
# [1] 5
# attr(,"match.length")
# [1] 6
substring(my.string, rx, rx+attr(rx, "match.length")-1)
# [1] "qwerty"