Ryan Turney

Ryan Turney

  • NA
  • 245
  • 208.8k

Regex Help

Jul 26 2007 12:52 AM
Hello, first off can anyone recommend a good way to learn Regex? And second, how can I use Regex to change the color to red for anything between two quotation marks? This is what I have.

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


Answers (1)