从R中的字符串中提取文本

时间:2015-01-31 02:48:06

标签: r string

我有以下字符串:

 x<-"\"stream;\"\" Well done; fans !!\"\";\"\"Boy\""

我在R中寻找语法,这使我能够从字符串中提取"Well done; fans !!"。 感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

通过gregexprregmatches功能。

> x<-"\"stream;\"\" Well done; fans !!\"\";\"\"Boy\""
> m <- gregexpr("\"[^\"]*\"", x)
> o <- regmatches(x, m)
> o[[1]][2]
[1] "\" Well done; fans !!\""

这将匹配所有双引号字符串并仅打印第二个值。