The following code return 1:
Regex.Match("aaa", "(a)").Groups[1].Captures.Count
But I expect to receive 3: I see three captures of a.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to either get the match count:
Or add a quantifier to the regex:
The regex
(a)matches only a singlea. In the first example above, that regex can be matched three times.In the second example the regex matches several
as at once and captures each one into group 1.To make a choice you should consider the following differences between them:
The second only yields two captures because it matches the first sequence of two
as but then it stops matching when it finds ab. The+quantifier only matches unbroken sequences.