1
I would like to know what is the best way to work with regular expression, so that it becomes 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 so all this code does not work, the color of the text does not change and neither the source!
And I wanted to know some commands of REGEX/C# because I did not find any tutorial that speaks of this in English.
Your question was a reference, here’s a http://aurelionet.regex/guide/
– Isvaldo Fernandes