2

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
  • i tried all but it returns TRUE always if any of the extension is present. Commented Jun 12, 2015 at 17:02

1 Answer 1

4

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 
Sign up to request clarification or add additional context in comments.

16 Comments

Still 4 mins to go :):)
If i need to check if txt orTXT and csv and xls, how can i do that
@Hashim Isn't that the condition in the question or do you need any in place of all?
@Hashim Based on the example showed, what do you want to return
i mean can i do ignore.case here with all
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.