我试图在一个句子中的两个单词之间得到文本。 例如,句子是 -
x <- "This is my first sentence and This is my second sentence"
现在我想输出如下:
[1] first second
这是我尝试过的,但它不起作用
gsub('^.*This is my \\s*|\\s*sentence.*$', '', x)
答案 0 :(得分:1)
试试这个:
x <- "This is my first sentence and This is my second sentence"
gsub('.*?This is my (\\w*?) sentence.*?', '\\1 ', x)