如何在字符串 R 中的两个单词之间获取多个文本?

How to get multiple text between two words in a string R?

我正在尝试获取句子中两个单词之间的文本。 比如句子是-

x <-  "This is my first sentence and This is my second sentence"

现在我想要这样的输出:

[1] first second

这是我尝试过的方法,但它不起作用

gsub('^.*This is my \s*|\s*sentence.*$', '', x)

试试这个:

x <-  "This is my first sentence and This is my second sentence"
gsub('.*?This is my (\w*?) sentence.*?', '\1 ', x)