Regex: Find Caps?

I need to find words within a document that exist entirely of all capitals (with exception of ‘I’ or “A”)

I’ve tried using the regex pattern:

This should work:

(?-i)\\b(?!A\\b|I\\b)\\p{Lu}+

Sometimes you can google specific uses and find the regex that works. It turns out finding comments /* like this */ is more complex than I thought but Google solved it for me :stuck_out_tongue:

[quote=202167:@Kem Tekinay]This should work:

(?-i)\\b(?!A\\b|I\\b)\\p{Lu}+ [/quote]

Testing the proposed solution, it still finds instances like “I” or “A” as single characters.

I’ve had success with “\b[A-Z]{2,}\b”

Explanation:
\b = word boundary
[A-Z] = caps A-Z
{2,} = 2 or more consecutive characters
\b = word boundary

But haven’t really tested it against a large group of data to see if there are instances where it will fail. What do you think Kem?

Thanks for the help guys! RegEx is a pain. Too bad there wasn’t a natural speech solution almost like SQL.

“SELECT * FROM GIVENINPUT WHERE words LIKE ALLCAPS AND LEN(words) NOT = 1” :-p

(Regex option for CaseSensitive is set to True)

Your solution is fine but will not match a word like “BER”. If that’s ok, then the only thing you have to add is the switch to make the pattern case-sensitive, or set the RegEx.Option.

If you do want to match any Unicode character, then try this:

\b\p{Lu}{2,}

[quote=202199:@Kem Tekinay]Your solution is fine but will not match a word like “ÜBER”. If that’s ok, then the only thing you have to add is the switch to make the pattern case-sensitive, or set the RegEx.Option.

If you do want to match any Unicode character, then try this:

\b\p{Lu}{2,}[/quote]

After putting it to the test, this was the best solution! Thanks a million Kem!