在R中,您可以使用
strsplit
函数按照分隔符(split
)来拆分向量,如下所示:x <- "What is this? It's an onion. What! That's| Well Crazy."
unlist(strsplit(x, "[\\?\\.\\!\\|]", perl=TRUE))
## [1] "What is this" " It's an onion" " What" " That's"
## [5] " Well Crazy"
我想使用R保留分隔符(split
),所以期望的输出应该是:
## [1] "What is this?" " It's an onion." " What!" " That's|"
## [5] " Well Crazy."
unlist(strsplit(x, "(?<=[?.!|])", perl=TRUE))
返回相同的结果。 - Jake Burkhead