简体   繁体   English

gsub提取两个单词

[英]gsub extract two words

I cannot get my head around gsub() . 我无法gsub() If text is: 如果文字是:

 text <- "Genus_species_1652_NL"

How would I extract to get 我将如何提取

"Genus species"

Thanks. 谢谢。 This is a useful link but I havnt been able to sort it http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SvetlanaEdenRFiles/regExprTalk.pdf 这是一个有用的链接,但我已经能够对它进行排序http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SvetlanaEdenRFiles/regExprTalk.pdf

You can do this like: 你可以这样做:

> gsub('([A-z]+)_([A-z]+)_.*', '\\1 \\2', text)
[1] "Genus species"

but as mentioned in a comment, a tool like strsplit may be more useful. 但正如评论中所提到的,像strsplit这样的工具可能更有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM