在R中,可以使用strsplit函数在定界符(split)上分割 vector ,如下所示:

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."

最佳答案

您可以使用"(?<=DELIMITERS)":

unlist(strsplit(x, "(?<=[?.!|])", perl=TRUE))

## [1] "What is this?"    "  It's an onion." "  What!"          " That's|"
## [5] " Well Crazy.

关于regex - R在定界符(分割)上分割,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21493081/

10-12 22:32