Home > database >  Extract specific strings
Extract specific strings

Time:06-09

I have already loaded the data in R from various sheets, below you can see the names of the sheets. Below you can see the data and code:

df<-data.frame(
                  Tables=c("Export_A1.xlsx","Export_A2.xlsx","Export_A10.xlsx"))

enter image description here

So now I want to extract specific names, or in other words, I want to remove the text "Export_" and ".xlsx". Below you can see an example

enter image description here

So can anybody help me how to solve this problem ?

CodePudding user response:

You can use the following code:

df$Tables <- gsub(".*[_]([^.] )[.].*", "\\1", df$Tables)

df

Output:

  Tables
1     A1
2     A2
3    A10
  • Related