I'm looking for a regex pattern that can limits matches based on maximum occurrences.
For example, match an alphanumeric string between 6-12 characters in length, and contains minimum 2, but NOT MORE THAN 4, uppercase letters, regardless of each of their positions in the string.
I've tried this pattern, but it only matches if the uppercase letters are located next to each other.
^([A-Z]{2,4}).{8,12}$
Valid matches would be:
HamBurger (2 uppercase, Length = 9)
LeTtUce (3 uppercase, Length = 7)
TACOss (4 uppercase, Length = 6)
But invalid matches would be:
ABCDE1234 (too many uppercase letters)
aBcDeFgHiJ (too many uppercase letters)
ADBC (length too short)
Thanks in advance for any assistance.