I'd like to know what is the best way to work with regular expression, so turn a code reader:
Example:
using System.Text.RegularExpression;
void LoadRegex(string filter, RichTextBox rtb, Color c){
var RTBmatch = Regex.Matches(rtb.Text, filter);
Color orig = rtb.SelectionColor;
int start = rtb.SelectionStart;
int length = rtb.SelectionLength;
foreach(Match m in RTBmatch){
rtb.SelectionIndex = m.Start;
rtb.SelectionLength = m.Length;
rtb.SelectionColor = c;
}
rtb.SelectionStart = start;
rtb.SelectionLength = length;
rtb.SelectionColor = orig;
}
MainForm.cs:
void FormLoaded(object o, EventArgs env){
var rtb = new RichTextBox();
rtb.Text = "if _0AB0>PRESSED!TRUE";
LoadRegex("if", rtb.Text, Color.Blue");
LoadRegex("_[0-Z]", rtb.Text, Color.DarkRed);
LoadRegex("PRESSED!TRUE", rtb.Text, Color.DarkBlue);
}
Even though all this code does not work, the text color does not change nor the font!
And I wanted to know some commands of REGEX / C # because I did not find any tutorial that speaks of this in Portuguese.