I have a string like this:
"19970101_AM23_popu_223_AZ1_Country.csv"
I want to extract every string before last underscore:
"19970101_AM23_popu_223_AZ1.csv"
I have tried this:
gsub("_.//*", "", x)
But got the same
"19970101_AM23_popu_223_AZ1_Country.csv"
Try
gsub("_\\w+$", "", x)