Hi
I'm try to change the background of the matched by a Regex text.
Example:
input: aaa aaa aaa //double white spaces in between
output: aaa aaa aaa //change the background of all matched white spaces to red
But it's coloring the wrong text.
I have tried and searched google for some days, but with no luck.
If I can get some help i'll be very grateful .This a WPF project in VS2013.
rtbClipboardContent is a RichTextBox.
The code I tried:
MatchCollection matches = Regex.Matches(text, RegexExpression);
rtbClipboardContent.Document.Blocks.Add(new Paragraph(new Run(text)));
foreach (Match m in matches)
{
TextPointer start = rtbClipboardContent.Document.ContentStart.GetPositionAtOffset(m.Index, LogicalDirection.Forward);
TextPointer end = rtbClipboardContent.Document.ContentStart.GetPositionAtOffset(m.Index + m.Length, LogicalDirection.Forward);
rtbClipboardContent.Selection.Select(start, end);
rtbClipboardContent.Selection.ApplyPropertyValue(Run.BackgroundProperty, "red");
}
Thanks in advance!