Who told you that Regex should be used everywhere or it's the best in this case? Use the tools only where they are most adequate.
In this very case, some non-Regex approach should be way easy and more maintainable. Pay attention: all your rules are not based on any certain patterns, they are only related to
multiplicity. Therefore, calculate number of characters classified into 3 classes: digits, letters and the rest of them. For that purpose, traverse the string in a
foreach
loop and increment one of the two counters (for digits and letters, the third count will be obtained by subtraction from the string
Length
), using two functions:
http://msdn.microsoft.com/en-us/library/7f0ddtxh.aspx[
^],
http://msdn.microsoft.com/en-us/library/yyxz6h5w.aspx[
^].
That's all. Simple, isn't it?
—SA