using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?<=where)(.*?)((ORDER BY|GROUP BY|HAVING|LIMIT|OFFSET|$).*)";
string input = @"select ""DIM_1"".""col1"",
""DIM_2"".""col2"" ,
""DIM_3"".""col3"" ,
""DIM_4"".""col4"" ,
""FAT_1"".""col5""
from ""FAT_1"",
""DIM_1"",
""DIM_2"",
""DIM_3"",
""DIM_4""
where ""DIM_1"".""col1"" IS NOT NULL
AND ""DIM_2"".""col2"" LIKE ('SUCCESS')
AND ""DIM_3"".""col3"" BETWEEN 20161213 AND 20161222
AND ""DIM_4"".""col4"" > 0
GROUP BY DIM_1.col1";
RegexOptions options = RegexOptions.Singleline | RegexOptions.IgnoreCase;
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