I am trying to write a Regex that will select everything between a whitespace and =.
From the following lines
Window x:Class="QuiddlerGUI.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
I would like it to select x:Class
and xmlns
. The closest I could get was this but it was not stopping at white space.
(?<=)(.*?)(?==)
I am using the regex to try and select text in a RichTextBox to attempt and change the color of the text.
foreach(TextColors color in textColors)
{
var start = body.Document.ContentStart;
while (start != null && start.CompareTo(body.Document.ContentEnd) < 0)
{
if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
{
var match = color.RegularExpression.Match(start.GetTextInRun(LogicalDirection.Forward));
var textrange = new TextRange(start.GetPositionAtOffset(match.Index, LogicalDirection.Forward), start.GetPositionAtOffset(match.Index + match.Length, LogicalDirection.Backward));
textrange.ApplyPropertyValue(TextElement.ForegroundProperty, color.TextColor);
start = textrange.End;
}
start = start.GetNextContextPosition(LogicalDirection.Forward);
}
}