private void LightText string pattern for while if else foreach for in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
private void LightText()
{
string[] pattern = { "for", "while", "if", "else", "foreach" };
for (int i = 0; i < pattern.Length; i++)
{
int pEdt = richTextBox1.SelectionStart;
MatchCollection match = Regex.Matches(richTextBox1.Text, pattern[i],
RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
foreach (Match nextmatch in match)
{
richTextBox1.Select(nextmatch.Index, pattern[i].Length);
richTextBox1.SelectionColor = Color.Blue;
}
richTextBox1.DeselectAll();
richTextBox1.Select(pEdt, 0);
}
}
}