ajeh
ajeh

Reputation: 2784

Regex for finding all uppercase words, excluding XYZ

Tried using the regex \b[A-Z][A-Z]+\b to find all uppercase words containing at least 2 uppercase letters. But there is one word that I am not interested in and it occurs too many times to skip it manually. How should I modify the regex to exclude that specific word?

Upvotes: 1

Views: 2345

Answers (1)

Abecee
Abecee

Reputation: 2393

Prefix your regex with a negative look ahead:

(?!XYZ)\b[A-Z][A-Z]+\b

RegEx101

Could do the "at least two" more explicitely like

(?!XYZ)\b[A-Z]{2,}\b

Upvotes: 3

Related Questions