title: Highlight words with RegEx on RichTextBox with SilverLight
body: <p>Im trying to highlight words, letters or anything marked in a Regular Expression.
  Im using RichTextBox in Silverlight (take care that Silverlight has NOT uses the same .NET Framework than others apps, for example it HAS NOT the TextRange)</p>
  
  <p>Everytime the text has a \r\n or \n\r the pointers moves 4 position forward. But the really bad is when i do the highlight, the style text add 4 positions more. Even, i think he has more erratic behavior than racional. Please advice me something in this!</p>
  
  <p>Thanks FailDev.</p>
  
  <p>The text im using for try this is:</p>
  
  <p>ffffffffffafffffffffff
  fffffafffffffffff
  fffffffffffffafffffffff</p>
  
  <p>(4 lines, after the last f there is a carrier return \ line feed)</p>
  
  <p>Also this one doesnt work with my code (has the erratic behavior, or not):</p>
  
  <p>ffffffffffaaffffffafffff
  fffffafffffffffff
  fffffffffffffafffffffff</p>
  
  <p>(4 lines, after the last f there is a carrier return \line feed)</p>
  
  <p>The idea is highlight with blue, bold and underline the "a" character.</p>
  
  <p>The last code that i tried is this:</p>
  
  <pre><code>MatchCollection CarrierReturns =  MainGeneral.Build_Regex(@"[\r\n|\n\r]", false);
  
              MatchCollection WordsFound =  MainGeneral.Build_Regex("[a]", false);
              foreach (Match x in WordsFound) {
                  int StringCarrierCount = 0;
  
                  if (CarrierReturns.Count &gt; 0)
                  {
                      foreach (Match CR in CarrierReturns)
                      {
                          if (x.Index &gt; CR.Index)
                          {
                              textBox1.Text += " CI:" + StringCarrierCount + "- ";
                              break;
                          }
                          StringCarrierCount++;
                      }
                  }
  
                  if (x.Index &lt; CarrierReturns[0].Index) { StringCarrierCount = 0; }
  
                  StringBegin = 2 + x.Index + (4 * StringColorCounter) + (4 *  StringCarrierCount);
                  StringEnd = StringBegin + x.Length;
                  textBox1.Text += StringBegin + "-" + StringEnd + " ";
                  StringColorCounter++;
  
                  StartPoint = MainData.ContentStart.GetPositionAtOffset(StringBegin, LogicalDirection.Forward);
                  EndPoint = MainData.ContentStart.GetPositionAtOffset(StringEnd, LogicalDirection.Forward);
                  MainData.Selection.Select(StartPoint, EndPoint);
                  MainData.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(Colors.Blue));
                  MainData.Selection.ApplyPropertyValue(Run.TextDecorationsProperty, TextDecorations.Underline);
                  MainData.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
              }
  </code></pre>
  
  <p>Thanks in advance, please ask me before rate bad! :)</p>