Regex to extract string from a file path R?

  • A+

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


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:


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" 


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


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