regex - 根据r中的模式提取部分字符串

标签 regex r

我想从列表中提取部分字符串。我不知道如何定义字符串的模式。感谢您的帮助。

library(stringr)
names = c("GAPIT..flowerdate.GWAS.Results.csv","GAPIT..flwrcolor.GWAS.Results.csv",
"GAPIT..height.GWAS.Results.csv","GAPIT..matdate.GWAS.Results.csv")
# I want to extract out "flowerdate", "flwrcolor", "height" and "matdate"
traits <- str_extract_all(string = files, pattern = "..*.")
# the result is not what I want.

最佳答案

您还可以使用正则匹配

> regmatches(c, regexpr("[[:lower:]]+", c))
[1] "flowerdate" "flwrcolor"  "height"     "matdate"   

我建议您不要使用 c 作为变量名,因为您正在覆盖 c 函数。

关于regex - 根据r中的模式提取部分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23306073/

相关文章:

r - 如何显示 R 中两个数据集不共享哪些变量?

reshape 矩阵以获得网络

Javascript 运行时错误 :

Python 正则表达式 - 删除标点符号但保留 <uk> 原样

xml - 如何使用 XSLT 从 XML 中删除某些属性

r - 如何使用 Shiny 的传单将多段线从一个位置分别添加到其他位置?

r - ggplot 上 geom_point 和 geom_smooth 的不同色标

正则表达式匹配文件路径的最后一部分

javascript - 替换/删除两个字符之间的所有内容

减少 RMarkdown/Quarto 中命令和输出之间的空间