karthik_19942017
karthik_19942017

Reputation: 49

How to subset uppercase text alone

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"

I need only "CUMIACC04" alone as output

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.

** 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.**

Upvotes: 0

Views: 123

Answers (1)

akrun
akrun

Reputation: 887193

We can use 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")

Upvotes: 2

Related Questions