x <- 'D:/r4ds/map.json/baishan.json'
I just wanna get "baishan".How can I realize it?
x <- 'D:/r4ds/map.json/baishan.json'
I just wanna get "baishan".How can I realize it?
You use basename
+ file_path_sans_ext
from tools
.
x <- 'D:/r4ds/map.json/baishan.json'
tools::file_path_sans_ext(basename(x))
#[1] "baishan"
Using pure regex :
sub('.*/(.*)\\..*', '\\1', x)
This extracts everything after last "/"
till the following dot ("."
).