How would I go about detecting if all alphabetic characters in a string (of >= 2 characters) are upper case? Ultimately, I'm trying to filter out chapter title names, that are rows in my data-set. So if a chapter title is "ARYA", I want that detected, same as "THE QUEEN'S HAND".
Here's what I'm trying but doesn't work:
library(dplyr)
library(stringr)
str_detect("THE QUEEN’S HAND", "^[[:upper:]]{2,}+$")
#> FALSE
The requirements I need:
- Number of characters >= 2 because I'm ultimately using this to filter out chapter names, but sometimes there's a row where the word is "I", but that's not a chapter -- it's just a word. Though this could be filtered at a different point
- Only alphabetic characters or apostrophes detected. Sometimes the row is "...", which I don't want detected. However, if I use a
toupper(x) == (x)
solution, this would be detected alongside something like "THE QUEEN'S HAND". I'm also trying to get rid of anything with exclamation points or periods, like "STOP THIS!"