Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.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
Regex 从字符串中删除多个句点_Regex_R_Gsub - Fatal编程技术网

Regex 从字符串中删除多个句点

Regex 从字符串中删除多个句点,regex,r,gsub,Regex,R,Gsub,我有一些类似的列名,例如: Eagles.....Brown.Bears....... Western.Bulls......Great.Lions.... 我想摘录这些词。例如,从第一个开始: 'Eagles' and 'Brown.Bears' 第二项: 'Western.Bulls' and 'Great.Lions' 团队名称之间总是有句点(>2个句点,但数量不同“..”),团队名称中总是有一个句点代替空格。我们可以使用stru extract library(stringr) s

我有一些类似的列名,例如:

Eagles.....Brown.Bears.......
Western.Bulls......Great.Lions....
我想摘录这些词。例如,从第一个开始:

'Eagles' and 'Brown.Bears'
第二项:

'Western.Bulls' and 'Great.Lions'

团队名称之间总是有句点(>2个句点,但数量不同“..”),团队名称中总是有一个句点代替空格。

我们可以使用
stru extract

library(stringr)
str_extract_all(str1, "\\w+(\\.\\w+)?")
#[[1]]
#[1] "Eagles"      "Brown.Bears"

#[[2]]
#[1] "Western.Bulls" "Great.Lions"  
或者使用
strsplit
from
base R

strsplit(str1, "\\.{2,}")
#[[1]]
#[1] "Eagles"      "Brown.Bears"

#[[2]]
#[1] "Western.Bulls" "Great.Lions"  
数据
str1我们可以使用
str\u extract

library(stringr)
str_extract_all(str1, "\\w+(\\.\\w+)?")
#[[1]]
#[1] "Eagles"      "Brown.Bears"

#[[2]]
#[1] "Western.Bulls" "Great.Lions"  
或者使用
strsplit
from
base R

strsplit(str1, "\\.{2,}")
#[[1]]
#[1] "Eagles"      "Brown.Bears"

#[[2]]
#[1] "Western.Bulls" "Great.Lions"  
数据
str1