Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove specific pattern in string?

Tags:

regex

r

gsub

I have data in that string is like f <- "./DAYA-1178/10TH FEB.xlsx". I would like to extract only DAYA-1178

what I have tried is

f1 <- gsub(".*./","", f) 

But it is giving last result of my file "10TH FEB.xlsx"

Appreciate any lead.

like image 613
Tushar Lad Avatar asked May 16 '26 18:05

Tushar Lad


1 Answers

It seems you are dealing with files. You need the basename of the directory:

basename(dirname(f))
[1] "DAYA-1178"

or you could do:

sub(".*/","",dirname(f))
[1] "DAYA-1178"
like image 117
KU99 Avatar answered May 18 '26 09:05

KU99



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!