Matching all the file extensions

43 views Asked by At

I have a vector of file extensions like (.txt,.TXT,.csv,.xls), i tried "\\.(TXT|txt|csv|xls)$" according to this which return TRUE if any of the extensions are present, however i am interested to return a TRUE if all the extensions are present in the vector otherwise FALSE. Thanks

1

There are 1 answers

16
akrun On BEST ANSWER

Try

 v1 <- c('a1.txt', 'a2.TXT', 'a3.csv', 'a22.txt', 'a13.TXT', 'a23.txt')
 ext <- c('txt', 'TXT', 'csv', 'xls')
 all(ext %in% sub('.*\\.', '', v1) )
 #[1] FALSE