【问题标题】:How to get multiple text between two words in a string R?如何在字符串R中的两个单词之间获取多个文本?
【发布时间】:2016-10-25 05:55:10
【问题描述】:

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

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

现在我想要这样的输出:

[1] first second

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

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

【问题讨论】:

    标签: r regex string gsub


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 2018-08-16
      相关资源
      最近更新 更多