6
Regular Expressions - classes and methods for implementing fast, complex string searches
lSearch text in richTextBox1 on form using regular expression in textBox1,
land show result by highlighting matches in bold font:
l
lMatchCollection Matches=Regex.Matches(richTextBox1.Text,
l textBox1.Text, RegexOptions.IgnoreCase |
l RegexOptions.IgnorePatternWhitespace |
l RegexOptions.ExplicitCapture);
l
lSystem.Drawing.Font currentFont = richTextBox1.SelectionFont;
lSystem.Drawing.FontStyle newFontStyle;
lnewFontStyle = FontStyle.Bold;
l
lforeach (Match NextMatch in Matches)
l{
l this.richTextBox1.SelectionStart=NextMatch.Index;
l this.richTextBox1.SelectionLength=NextMatch.ToString().Length;
l richTextBox1.SelectionFont = new Font(currentFont.FontFamily,
l currentFont.Size, newFontStyle);
l};