Dim myMatches As MatchCollection
Dim myPatterns As String() = {"(Purchase Cost:)", "(Sales Cost)"}
Dim myColors As Color() = {Color.Blue, Color.Red}
RichTextBox1.SelectAll()
RichTextBox1.SelectionColor = Color.Black
For i As Integer = 0 To myPatterns.Length - 1 Step 1
myMatches = New Regex(myPatterns(i), RegexOptions.Singleline).Matches(RichTextBox1.Text)
For j As Integer = 0 To myMatches.Count - 1 Step 1
RichTextBox1.Select(myMatches(j).Groups(1).Index, myMatches(j).Groups(1).Length)
RichTextBox1.SelectionColor = myColors(i)
Next
Next
|