我想要第二句话的文字。
text="I need to go to mall today. I want to purchase clothes. Also, I want to buy shoes."
预期结果:
I want to purchase clothes. Also, I want to buy shoes.
答案 0 :(得分:0)
strsplit()
的可能性:
sapply(strsplit(text, ". ", fixed = TRUE),
function(x) paste(x[2:length(x)], collapse = ". "))
[1] "I want to purchase clothes. Also, I want to buy shoes."
答案 1 :(得分:0)
我们还可以使用stringr::str_match
捕获第一个点之后的所有内容。
stringr::str_match(text, "\\.(.*)")[, 2]
#[1] " I want to purchase clothes. Also, I want to buy shoes."
[, 2]
用于获取捕获组。
答案 2 :(得分:0)
我们可以将base R
与sub
一起使用,以匹配非.
后跟.
的字符和空格(如果有的话),并用空格({{1} })
""
,而sub("^[^.]+\\.\\s*", "", text)
#[1] "I want to purchase clothes. Also, I want to buy shoes."
中的等效选项将为
tidyverse