【发布时间】:2021-04-06 02:39:50
【问题描述】:
我有一些句子的分隔模式是“(has|is|thinks)”
我想在第二句中包含分隔符并删除所有尾随空格,如下所示:
mystr1 <- "the bird is now a dog"
mystr2 <- "the small cow thinks like a dog"
mystr3 <- "the fish has become a dog"
结果:
"the bird" "is now a dog"
"the small cow" "thinks like a dog"
"the fish" "has become a dog"
注意:
str_split(mystr3, "(has|is|thinks)", n = 2)
导致
"the f" "h has become a dog"
因为“is”是一个分隔符并且是“fish”的一部分
如何最好地做到这一点?
【问题讨论】: