RichTextBox
rtb = (RichTextBox)_tabs.SelectedTab.Controls[0];Regex r = new Regex("([\\t{}();])"); String[] tokens = r.Split(line); foreach (string token in tokens)
{
if token.StartsWith("\"") && token.EndsWith("\""))
{
int index = line.IndexOf("\"");
string quote = line.Substring(index, line.Length);
rtb.SelectionColor = Color.Red;
rtb.SelectionFont = new Font("Courier New", 10, FontStyle.Regular);
rtb.SelectedText = quote;
break;
}
rtb.SelectedText = token;
}
Thanks
Jan MontanoPosted Jul 26, 2007, 5:24 AM
I guess the best way to really learn Regex is by reading documents about it and practicing it yourself, coming up with formats to construct a regex like ip address, telphone#, url links etc...
I'm not that familiar with the richtextbox control. But I'll give the regex a try. First, the regex pattern you're looking for is:
Regex pattern = new Regex("\"[^\"]+\"");
To be able to get the occurences of each regex:
MatchCollection matchCollection = pattern.Matches(line);
pattern.Matches() will give you an array specifying each position/index the pattern occured. I hope that with the index and length of each occurence returned, you'll be able to modify the color of your richtextbox