I can’t find a working regex in python to split these strings:
CAT One | desired: CAT
DOG SILVER FOX Two | desired: DOG SILVER FOX
KING KONG | desired: KING KONG
P'OT THEN Mark First | desired P'OT THEN
Just stupid examples, but i need to separate words that are full uppercase from words that are only capitalized.
I could have {1,n} uppercase words and {0,n} capitalized words.
My regexs were too weird, i catch all the string or only one uppercase word..
Output:
Explanation:
\b[A-Z]+means: match one or more capital letters, but only at the start of a word. This will match “YELLOW”, but not the “E” in “horsE”.\W*[A-Z]+means: match zero or more non-word characters, followed by one or more capital letters. This will match “‘OT” or “-BAR” or ” KONG”.(?:\W*[A-Z]+)*\bmeans: make a (non-capturing) group which matches zero or more times, but only at the end of a word. This will match ” SILVER FOX”, but not the ” T” which follows it.