I have data with plenty of text strings where key words and phrases are capitalised. I want to extract the capitalised bits, but NOT breaking down capitalised phrases into their constituent parts. Some pseudocode explains best:
text = "Here is some text where KEY words and EXTENDED PHRASES are in UPPER CASE.";
< SOME ELEGANT CODE EXTRACTS...>
{"KEY", "EXTENDED PHRASES", "UPPER CASE"}
…but does not break the extended phrases into their constituent parts. So the result is NOT…
Since posting, it also occurs to me I will need to include words which are all upper case but which include certain punctuation. So, the following should also be considered upper case:
DON’T
NON-EXISTENT
R2D2
and so on. But I think I can fix it myself, using your example as a springboard.
text = “This is a TEXT with QQ or Q or QQQ or some UPPER CASE WORDS to test a FUNCTION”
DeleteCases[ StringTrim@StringCases[text, Longest[WordBoundary ~~ (_?UpperCaseQ | WhitespaceCharacter) .. ~~ WordBoundary]], “”]
This gives
{“TEXT”, “QQ”, “Q”, “QQQ”, “UPPER CASE WORDS”, “FUNCTION”}