In the code below, the match collection grabs all of the matching items in a string but the select doesn't hightlight the last one.
if (input.Text.Length > 0) {
Regex r = new Regex(regex.Text);
MatchCollection mc = r.Matches(input.Text);
formatted.Text = mc.Count.ToString();
int count;
for (count = 0; count < mc.Count; ++count) {
input.SelectionBackColor = Color.Yellow;
input.Select(mc[count].Index, mc[count].Length);
}
}
if (input.Text.Length > 0) {
Regex r = new Regex(regex.Text);
MatchCollection mc = r.Matches(input.Text);
formatted.Text = mc.Count.ToString();
int count;
for (count = 0; count < mc.Count; ++count) {
input.SelectionBackColor = Color.Yellow;
input.Select(mc[count].Index, mc[count].Length);
}
}