Amitai Amitai - 1 year ago 61
R Question

R regex for everything between LAST backslash and last dot

full.path = 'C:\Users\me\Desktop\Data\my_file.csv'

I can't figure out the right regex to be left with only = 'my_file'

I'm afraid I keep on failing on encoding correctly the last backslash

Answer Source

We can use the basename and file_path_sans_ext (from tools) to extract the file name

#[1] "my_file"

Or if we need regex, use gsub

gsub(".*\\\\|\\..*$", "", full.path)
#[1] "my_file"


full.path = 'C:\\Users\\me\\Desktop\\Data\\my_file.csv'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download