using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?i)(?:\w+\W+){0,9}?(?=.*(?:plot).*|.*(?:over).*)(?:\w+\W+){0,9}?(?=Charlie|Muir|Charlie Muir)\K(?:(?:Charlie|Muir|Charlie Muir)\s+)+";
string input = @"
cHarlie muir charlie charlie was over the moon the the the the the tge the the the
-the the the the the the the the the the the the the the the the the-
over was the the the moon parker parker charlie muir charlie
-the the the the the the the the the the the the the the the the the-
Charlie muir charlie was near the plot
-the the the the the the the the the the the the the the the the the-
ChArlie was far away from the plot was far away from the
-the the the the the the the the the the the the the the the the the-
the plot was far away from CharLie
-the the the the the the the the the the the the the the the the the-
the plot was far away from CharLie muir charlie
-the the the the the the the the the the the the the the the the the-
the over was far away from CHarlie muir
-the the the the the the the the the the the the the the the the the-
Mr cHARLIE was bowled over test was bowled after the ball
-the the the the the the the the the the the the the the the the the-
over the test was bowled muIR
-the the the the the the the the the the the the the the the the the-
the plot the ball the slot it will plot the test was bowled MuiR
-the the the the the the the the the the the the the the the the the-
";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx