I stumbled upon this seemingly trivial question, and I was stuck on it. I have a line in which I want to match all uppercase words in one regular expression , only if somewhere in the line there is at least a lowercase letter.
Basically, I want each of these lines (we can consider that I will apply the regular expression for each line separately, I don’t need to use some multi-line processing):
ab ABC //matches or captures ABC
ab ABC 12 CD //matches or captures ABC, CD
ABC DE //matches or captures nothing (no lowercase)
ABC 23 DE EFG a //matches or captures ABC, DE, EFG
AB aF DE //matches or captures AB, DE
I use PCRE as a regex fragrance (I know that some other fragrances allow you to watch with variable lengths).
Update after comments
Obviously, there are many simple solutions if I use several regular expressions or the programming language I use to call a regular expression (for example, first check the string looking for a lowercase letter, and then match all the uppercase words with two different regular expressions) .
My goal here is to find a way to do this with a single regex.
I have no technical imperative for this limitation. Take this as a style exercise if you need, or curiosity, or I try to fulfill my regular expression skills: the task seemed (at first) so simple that I would like to know if only one regular expression can do it. If he cannot, I would like to understand why.
, , , , , - , , " ", , .
, ?