Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R-抽取词中的正则表达式_R_Regex - Fatal编程技术网

R-抽取词中的正则表达式

R-抽取词中的正则表达式,r,regex,R,Regex,假设我有以下文本: text='祝你今天愉快,@你好,伯斯先生的家人 如何仅从R中带有正则表达式的句子中提取@hello?一个选项使用gsub: text <- 'have a nice day, @hello, mr burs' x <- gsub('.*(@\\w+).*', '\\1', text) x [1] "@hello" text您尝试了什么?请参见此处开始:stru extract也是一个不错的选择:stringr::stru extract(文本“@\\w+”)

假设我有以下文本:

text='祝你今天愉快,@你好,伯斯先生的家人


如何仅从R中带有正则表达式的句子中提取@hello?

一个选项使用
gsub

text <- 'have a nice day, @hello, mr burs'
x <- gsub('.*(@\\w+).*', '\\1', text)
x

[1] "@hello"

text您尝试了什么?请参见此处开始:
stru extract
也是一个不错的选择:
stringr::stru extract(文本“@\\w+”)