Skip to main content
2 of 2
deleted 4 characters in body
Wiktor Stribiżew
  • 630.9k
  • 41
  • 502
  • 632

You can change the code to

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(.*?)(?=\s+and|$)", RegexOptions.IgnoreCase); 

and it will only capture the where clause up to the next and or the end of the query.

Wiktor Stribiżew
  • 630.9k
  • 41
  • 502
  • 632