If there are both upper cases and lower cases text how to subset only upper cases text alone in that.
如果同时存在大写和小写文本,那么如何仅将大写文本单独分组。
For example: consider there is a text like this "Cumi Speed CUMIACC04 Mar 04"
例如:考虑有这样的文字“Cumi Speed CUMIACC04 Mar 04”
I need only "CUMIACC04" alone as output
我只需要“CUMIACC04”作为输出
Secondly consider I have a set of links for example:
其次考虑我有一组链接,例如:
http://www.industrybuying.com/abrasive-cloth-rolls-norton-AB.CO.AB6.388773/
I need to get the last part of the link that is -"AB.CO.AB6.388773/" alone how to subset and do this in R programming.
我需要得到链接的最后一部分 - “AB.CO.AB6.388773 /”单独如何在R编程中进行子集化和这样做。
** strsplit is one of the option that I tried but the length of the links is varying so I am not able to get proper result so how to solve this in R programming.**
** strsplit是我尝试的选项之一,但链接的长度是变化的,所以我无法得到正确的结果,所以如何在R编程中解决这个问题。**
1 个解决方案
#1
2
We can use str_extract
我们可以使用str_extract
library(stringr)
str_extract(str1, "\\b[A-Z.]+[0-9.]*\\b")
#[1] "CUMIACC04" "AB.CO.AB6.388773"
data
str1 <- c("Cumi Speed CUMIACC04 Mar 04", "Cumi Speed AB.CO.AB6.388773/ Mar 05")
#1
2
We can use str_extract
我们可以使用str_extract
library(stringr)
str_extract(str1, "\\b[A-Z.]+[0-9.]*\\b")
#[1] "CUMIACC04" "AB.CO.AB6.388773"
data
str1 <- c("Cumi Speed CUMIACC04 Mar 04", "Cumi Speed AB.CO.AB6.388773/ Mar 05")