I’m making a small tool. The code below fires when the large RichTextBox is updated.
How can I modify this code to highlight #703919 in Color.ForestGreen, not only #?
I’d like to keep the code as concise as possible.

private void CSS_TextChanged(object sender, EventArgs e)
{
CSS.Select(0, CSS.TextLength);
CSS.SelectionColor = CSS.ForeColor;
string[] Keywords = {"background", "filter", ":", "#"};
Color[] Colours = {Color.DarkBlue, Color.DarkBlue, Color.Magenta, Color.ForestGreen};
for(int i = 0; i < Keywords.Length; i++)
{
int Pointer = 0;
int Index = 0;
while(true)
{
Index = CSS.Text.IndexOf(Keywords[i], Pointer);
if(Index == -1)
break;
CSS.Select(Index, Keywords[i].Length);
CSS.SelectionColor = Colours[i];
Pointer = Index + Keywords[i].Length;
}
}
}
It depends on how flexible you want to be.
A simple solution would be to not take the length of the highlight area from the keyword but from some other source:
Please note that this is really a very simple implementation. It only works as long as there are always exactly 6 digits after the hash sign.
Other alternatives would be: