using System.Text.RegularExpressions;
namespace RegularExpressionPlayground
const string text = "Professional C# 6 and .NET Core 1.0 provides complete coverage " + "of the latest updates, features, and capabilities, giving you " + "everything you need for C#. Get expert instruction on the latest " + "changes to Visual Studio 2015, Windows Runtime, ADO.NET, ASP.NET, " + "Windows Store Apps, Windows Workflow Foundation, and more, with " + "clear explanations, no-nonsense pacing, and valuable expert insight. " + "This incredibly useful guide serves as both tutorial and desk " + "reference, providing a professional-level review of C# architecture " + "and its application in a number of areas. You'll gain a solid " + "background in managed code and .NET constructs within the context of " + "the 2015 release, so you can get acclimated quickly and get back to work.";
public static void Find1(string text)
Console.WriteLine(nameof(Find1) + "\n");
const string pattern = @"\ba\S{8}ure\b";
MatchCollection matches = Regex.Matches(text, pattern, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
WriteMatches(text, matches);
public static void WriteMatches(string text, MatchCollection matches)
Console.WriteLine($"Original text was: \n\n{text}\n");
Console.WriteLine($"No. of matches: {matches.Count}");
foreach (Match nextMatch in matches)
int index = nextMatch.Index;
string result = nextMatch.ToString();
int charsBefore = (index < 5) ? index : 5;
int fromEnd = text.Length - index - result.Length;
int charsAfter = (fromEnd < 5) ? fromEnd : 5;
int charsToDisplay = charsBefore + charsAfter + result.Length;
Console.WriteLine($"Index: {index}, \tString: {result}, \t" + $"{text.Substring(index - charsBefore, charsToDisplay)}");