I have a string that can only be composed of X
uppercase and -
.
Example: X-XX-XX
or X-X-X-XX-XXX
. Where every -
would count one group and each X
one digit.
Example 1: The string X-XX-XX
has 3 groups, the first group contains 1 digit, the second contains 2 digits, and the third contains 2 digits.
Example 2: The string X-X-X-XX-XXX
has 5 groups, the first group contains 1 digit, the second contains 1 digit and the third contains 1 digit, the fourth contains 2 digits and the fifth contains 3 digits.
How do I get the information as described in Example 1 and 2.
I have tried this, to count the number of groups:
public static int ValidaMascaraPlanoDeContas(string Mascara)
{
var regex = new Regex(@"([X])\w+/g");
var match = regex.Match(Mascara);
return match.Groups.Count;
}
I've tried several string patterns and nothing, as I'm stuck in the group I do not know the procedure for counting the digits of each group.