I'm trying to parse an sql where I would like to get the where clause of the statement.
Below is the piece of code I have written:
string input = "select * from table where x = 5 and abc = 'p' or def = 1 order by col";
Match match = Regex.Match(input, @"select.*from [a-z]+ where(.*)(?:order by .*)?",RegexOptions.IgnoreCase);
But here the output I get includes the order by statement which I dont want. I get the expected output if I removed last '?', but the input statement might or might not contain order by.
Expected Output: " x = 5 and abc = 'p' or def = 1 "
can you please correct my regex