1
Answer

Regex Help

Ryan Turney

Ryan Turney

17y
2.2k
1
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)