如何仅识别由“连接”组成的单词-&引用;在R?

如何仅识别由“连接”组成的单词-&引用;在R?,r,string,R,String,让我们假设,我在R中有以下文本: x = "The effects in the medium-term of an appreciation of the exchange rate are still to be carefully assessed in our projections. However, we can observe in the short-term that the our pogramme of purchasing asset-backed securi

让我们假设,我在R中有以下文本:

x = "The effects in the medium-term of an appreciation of the exchange rate are still to be carefully assessed in our projections. However, we can observe in the short-term that the our pogramme of purchasing asset-backed securities had a positive impact on overall economic activity"

我如何才能只获得以下信息:

# medium-term
# short-term
# asset-backed 

基本上,我只需要提取那些由“-”链接的单词

有人能帮我吗

谢谢

这是否有效:

library(stringr)
str_extract_all(x, '\\b[a-z]+-[a-z]+\\b')[[1]]
[1] "medium-term"  "short-term"   "asset-backed"

在base R中,您可以使用:

regmatches(x, gregexpr('\\w+-\\w+', x))[[1]]
#[1] "medium-term"  "short-term"   "asset-backed"

非常感谢你们两位。如果SO允许,我将标记正确答案。我通常会给得分最低的受访者打分。再次感谢!