Regex to extract string from a file path R?

  • A+
Category:Languages

I have the following file path with uuid incapsulated within it's path:

"~/My_Files/F0/F1/F2/0b27ea5fad61c99d/0b27ea5fad61c99d/2015-04-1-04-25-12-925"

I want to extract it using regular expression. I know that I can just unlist(strsplit(string, "/")) and take the 7th element but it seems to me too slow and not efficient problem solving.

Here is what I have tried so far:

/w{16} 

I am keep trying to play with this, please advise.

I want to extract the uuid: 0b27ea5fad61c99d

 


Here's a slightly hacky but compact and regex-free solution:

basename(dirname(x)) #[1] "0b27ea5fad61c99d" 

Where

x <- "~/My_Files/F0/F1/F2/0b27ea5fad61c99d/0b27ea5fad61c99d/2015-04-1-04-25-12-925" 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: