I am trying to match all consecutive all caps words/phrases using regex in Python. Given the following:
text = \"The following words are ALL CAPS. The follow
Keeping your regex, you can use strip() and filter:
strip()
filter
string = "The following words are ALL CAPS. The following word is in CAPS." result = filter(None, [x.strip() for x in re.findall(r"\b[A-Z\s]+\b", string)]) # ['ALL CAPS', 'CAPS']