tags:

views:

145

answers:

3

Hi, Im making a regex expression using C# to extract the where clause of a sql expression. The whre clause can have multiple columns with different operators. Though NO grouping is allowed in the sql e.g.

col1 = 5 and (col3 = 6 or col4 < 5)

Only a simple format is allowed in the sql:

col1 = 5 and col1 < 6 or col3 <> ?

I have been trying to do it with the following , but the "and" and "or" keywords seem to be caught, and it doesnt capture all:

.*?(?<columnname>.+?)(?<operator>=|<|>|<>)(?<value>.+?)\s
+2  A: 

Are you sure you don not want a complete parser that will save you a lot of time (i.e. the time others have put into it)?

soulmerge
A: 

Am I missing something here? "to extract the where clause of a sql expression" Why not simply capture whats between the where keyword and either group by or end of line:

where(.*?)(group|\Z)

ennuikiller
Should probably add order in there too, where(.?)(group|order|\Z)
Mark
Because im making a general solution for a particular source system (Navision) and the source columns are translated into other languages or renamed so almost no two sources are the same. I need to be able to replace the column names with the ones i know fits the particular solution
H4mm3rHead
+1  A: 
Adam Bellaire