/// <summary> /// Search the contents of the file. /// </summary> /// <param name="regex">The regular expression to search for.</param> /// <param name="foregroundColor">The foreground color the matches should be drawn in.</param> /// <param name="backgroundColor">The background color the matches should be drawn in.</param> private void Search(Regex regex, ConsoleColor foregroundColor, ConsoleColor backgroundColor) { try { MatchCollection matches = regex.Matches(_fileContents); int startIndex; int endIndex; foreach (Match m in matches) { startIndex = m.Index; endIndex = m.Index + m.Length; if (endIndex > startIndex) { var cs = new ColoredSubstring(m.Index, m.Index + m.Length, foregroundColor, backgroundColor); _substrings.Add(cs); } } } catch (ArgumentException ex) { // Do nothing } }