Find multiple, non consecutive, occurrences of a character in string

Viewed 2607

Can somebody please help me write RegEx expression which can check if a string contains more than one occurrence of a uppercase (or lowercase, doesn't matter) letter but not in a row. I need to have at least two (or even better n) occurrences in a string. If n=2 valid situations would be PassWord or PAssword or PASSWord.

When I tried this /(?=([A-Z]{2,3}))/g it matched PassWOrd but not PassWord.

What is strange to me is that it also matched PaSSWOrd. I thought 3 in {2,3} actually means that no more that 3 Uppercase characters will be matched. Why is SSWO matched?

I tried similar variations but non of them worked for me (nothing strange as i'm not very familiar with RegEx).

Can this be done using RegEx?

1 Answers
Related