Regex: Find whole words that have only uppercase letters in text
-
Je la regarde d'un air évocateur, AVEC des yeux dont elle ne se rend PAS compte non plus.
I must find only the whole words that have only uppercase letters in text.
OUTPUT:
AVEC
,PAS
Can I use regex?
-
@rodica-F said in Regex: Find whole words that have only uppercase letters in text:
Can I use regex?
Yes, I have created a regex which works. It’s probably not the prettiest but appears to select ONLY what you want.
I used the “Mark” function and entered:
Find What:(?-i)[A-Z]+(?![a-z])
So the
-i
means the regex is case sensitive (officially it says not case insensitive). The lookahead says that when we have grabbed ALL the uppercase characters there aren’t any remaining lowercase characters left in the word.See if that helps.
Terry
-
@Terry-R said in Regex: Find whole words that have only uppercase letters in text:
It’s probably not the prettiest but appears to select ONLY what you want.
I did some more testing and can see it will fail in some situations. See my image below for an example. I’m english speaking and unforunately accented characters are foreign to me. So it will likely fall to another seasoned forum member ( @guy038 generally comes thru with the goods) to provide a better solution.
Terry
-
@Terry-R thank you
-
Also, anothe regex can be this one (find whole words that have only uppercase)
Find:
\b[A-Z]\w+[A-Z]\b
(use Match Case)or simple"
FIND:
(?-i)\b[A-Z]\w+[A-Z]\b
-
@Terry-R said in Regex: Find whole words that have only uppercase letters in text:
I did some more testing and can see it will fail in some situations.
I have had more time to consider how it might work and also to look at “classes”. This next solution is I think working correctly and will also allow for words with a
'
in them such as DON’T.
Find What:(?-i)\b[[:upper:]](?:[[:upper:]]|')+\b
I had to start it with a look for an upper character, otherwise it would select just a
'
by itself. You may also want to extend to include a-
if you need to. If adding a-
then it becomes(?-i)\b[[:upper:]](?:[[:upper:]]|'|-)+\b
.Terry