I have the following list:

l={"apple","orange","kiwi","APPLE","lemon"}

How can I make a command so the capitalised word would be returned? So in this case the output should be

{"APPLE"}

Surely one can do l[[4]] but this is not what I am looking for, I want to have a command to search on a long list and return the capital words. Also note that in my case the whole word is in capital letter not only the first letter. Also assume that I don't know what would be the capital word, I just know that I have a list and somewhere in it there is a capitalised letter word, I need to find those.

up vote 7 down vote accepted
l = {"apple", "orange", "kiwi", "APPLE", "lemon", "Lemon", "leMon"};
Select[l, UpperCaseQ]

{"APPLE"}

  • Ah, I need to recalibrate my gedanken Mathematica; I didn't know that plain UpperCaseQ[] will still work! :) – J. M. is computer-less Oct 12 at 11:55
  • @J.M. my gedanken mma would have tried #==ToUpperCase[#]&:) – kglr Oct 12 at 12:00

Try

Select[l, StringMatchQ[__?UpperCaseQ]]

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.